Re: [PATCH] x86: coco: mark cc_mask as __maybe_unused

From: Huang, Kai
Date: Thu Mar 06 2025 - 00:38:57 EST



>
> > warn about them at all unless it's explictly enabled, and then
> > it warns about both of them. Newer gcc versions have a distinct
> > -Wunused-const-variable=1 for the clang behavior and
> > -Wunused-const-variable=2 that warns for both, so we could
> > reasonably decide to enable the =1 version by default and
> > leave the =2 version for W=2.
> >
> > On the other hand, most of the users of 'static const' variables
> > in headers are rather dumb and should just be moved into the
> > file that uses them, or they can be replaced with a #define
> > or an enum.
> >
> > In this case, the only user is a macro:
> > #define _PAGE_CC (_AT(pteval_t, cc_mask))
> >
> > so maybe '#define cc_mask 0' would be appropriate.
>
> Sounds a lot better to me.
>

I actually tried this with CONFIG_ARCH_HAS_CC_PLATFORM off yesterday but got
below error:

$ make -j$(nproc)
mkdir -p /work/enabling/src/linux/tools/objtool && make
O=/work/enabling/src/linux subdir=tools/objtool --no-print-directory -C objtool
CALL scripts/checksyscalls.sh
INSTALL libsubcmd_headers
CC drivers/char/tpm/tpm2-cmd.o
CC drivers/char/tpm/tpmrm-dev.o
CC drivers/char/tpm/tpm2-space.o
CC drivers/char/tpm/tpm-sysfs.o
In file included from ./arch/x86/include/asm/pgtable.h:23,
from ./arch/x86/include/asm/tlbflush.h:16,
from ./arch/x86/include/asm/uaccess.h:17,
from ./include/linux/uaccess.h:12,
from ./include/linux/sched/task.h:13,
from ./include/linux/sched/signal.h:9,
from ./include/linux/rcuwait.h:6,
from ./include/linux/percpu-rwsem.h:7,
from ./include/linux/fs.h:33,
from ./include/linux/tpm.h:23,
from drivers/char/tpm/tpm.h:27,
from drivers/char/tpm/tpm2-cmd.c:14:
drivers/char/tpm/tpm2-cmd.c: In function ‘tpm2_find_cc’:
./arch/x86/include/asm/coco.h:28:17: error: expected identifier or ‘(’ before
numeric constant
28 | #define cc_mask 0
| ^
drivers/char/tpm/tpm2-cmd.c:813:13: note: in expansion of macro ‘cc_mask’
813 | u32 cc_mask;
| ^~~~~~~
drivers/char/tpm/tpm2-cmd.c:816:17: error: lvalue required as left operand of
assignment
816 | cc_mask = 1 << TPM2_CC_ATTR_VENDOR | GENMASK(15, 0);
| ^


Rename the local variable 'cc_mask' in drivers/char/tpm/tpm2-cmd.c fix the
build, but I think the real issue is the 'cc_mask' in asm/coco.h is too common
to be a global visible variable/macro.