From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B2ABE7716D for ; Wed, 4 Dec 2024 07:24:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 428576B007B; Wed, 4 Dec 2024 02:24:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D8546B0082; Wed, 4 Dec 2024 02:24:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 279386B0083; Wed, 4 Dec 2024 02:24:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 057096B007B for ; Wed, 4 Dec 2024 02:24:51 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2D4AC120E02 for ; Wed, 4 Dec 2024 07:24:50 +0000 (UTC) X-FDA: 82856439246.11.801CA5B Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf19.hostedemail.com (Postfix) with ESMTP id B22D31A0005 for ; Wed, 4 Dec 2024 07:24:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=d3zxwTOn; spf=pass (imf19.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.128.53 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733297077; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=q7HALTGcIVNAPzHCr/BGJOOtFQkHmcHLgf3NzrBrnCw=; b=cTzuBvfECzndZe52sIRXZ9465gUm6OEtXNNz8ZZCfTe8rmU2lkq3YXN5hYmJGAQA6yXivz qfORroUKdJQKcWNpWdEfsETreIjLS7UoWoN2KQPdYoRhizZm8s52xEA9lt7yHb8evp4Sqo Px1yVDaZoSdxWd/dC5Kk5vh/Z16jFwI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733297077; a=rsa-sha256; cv=none; b=WGFh4sdMN8HrUn6tihyskLjj/VUYbRFxBmGY3/25olqwFwHy1j5o6jim7XGU+8pkdq9OaC MlSMXzcwe1wgaY6ZRNQO5evJ+W9L9qjoCm7xFtBeJiyAk0J8SiZmboBaOHH6q00ImNyFxV /AZ66cjWsOS5UOpVRRydn5Q1e978CMc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=d3zxwTOn; spf=pass (imf19.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.128.53 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org; dmarc=pass (policy=none) header.from=linaro.org Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-434a7ee3d60so2853815e9.1 for ; Tue, 03 Dec 2024 23:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733297085; x=1733901885; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=q7HALTGcIVNAPzHCr/BGJOOtFQkHmcHLgf3NzrBrnCw=; b=d3zxwTOnsDDp5a7sIFrbL9vXL6wP9Qxnw3oMMOje45PtNyOkel0r/NceeLVmhBLGnB XpSyVKUg7j4Bldewc8tR5ztDwF92IhemEBWZFX9AcZfQHvllzeHbi2TnKtCtjXjCcwJo OGINVv1YBaNeRRdi5e/sBzeibW4NzZThiXFEu+IDF6DCVQw0CDR4H8zfCoGMpWYj2UlE NhhjcLcc6yvx3GJ16WQz+gWe6g6dDy7Gvb06EOCu2uKugIaXHc/GRUf/gI5i6ncNXwEr kMUiDIoqvxa5iorrWdbBEmagv53DYAt8YHmEr1JNKnjQYW0Pw+x5BOIZtdEb0ubBsKUI fSTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733297085; x=1733901885; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=q7HALTGcIVNAPzHCr/BGJOOtFQkHmcHLgf3NzrBrnCw=; b=l3jyQYuE/ZCkAThYLg4D9oAhIPraiD9tmlvE11PfpyVoUd1RLO8agio/pdMZRLwHrY iZjH7biiH/uDDcYpkyoRvKbWlTSv4640E+f0LFDYNn+Jqzjkg3Yg5P05R5GHb7QmyvIa cMHA/r9st8+2ZphdJm3kebBg9PEPZgjDZ+FFaXFF5oWGUWrKCkEiAklW5xq8AfbJPj02 1yMjagi9IG2R5AagwlBHd99cCxz/Hz5OiI8xbqiHZtPpaPUff7ZPhpgo5C3rw1CLyEke R9iNye3wCZ4rtHFGpBeiUC82uMvRxLZPH/quOq5+Q7JW993oC7WrVDitx2d5cvQVVvyq eIfw== X-Forwarded-Encrypted: i=1; AJvYcCXn1aijozV4n7nlAJwQTD1OdzlEJvTWiFoMT+dxLumZo0AT6Q9cuchl08qhIs/TFxt+CsrlGgSlmw==@kvack.org X-Gm-Message-State: AOJu0YxKZGMLnfGGqgjIuxLr4aIMq02PcVxN0xYz9ysCGKnhPdKyZchN RxKWovX0djmVE1Sybv78p/NB1DuEcoElyDtnH8QVoyGep7cYVRRNxCmwRGr2ofI= X-Gm-Gg: ASbGncs1CfJ1e9fgt4TX+n1Kjkk9Su60Em/vQgORmLYmeDWFdAyJQzRsv8gnquKfNqL 2SNpoRvPdjAhd7y89iwX4MWSeiF6+UEJfQQS1o5SbHBV2fAw7XhzGitbg9W2GkCd5pfhUVTqcRd jt+Z5QgeeGXCthE2f9BDe9JSxxDi2+1CpF5T69LpG9KOcVq+R1QQ5k68Mi5CBF/8JHtxB1cXD5z 7OGSrZm8JZMPPbp2POADiIa5meFibA+qw5LkxFM5ifuRXJl5klcTHI= X-Google-Smtp-Source: AGHT+IHZjJV3X8DRwpZM2LIoO92mMGlR//mHmz04yaqsi0BXvmxHIJLtu+q3X/2NMlr6oqVbQxPx4A== X-Received: by 2002:a5d:64e6:0:b0:385:dedb:a15b with SMTP id ffacd0b85a97d-385fd9ac147mr4271554f8f.24.1733297085485; Tue, 03 Dec 2024 23:24:45 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-385ccd3a410sm17723351f8f.46.2024.12.03.23.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 23:24:44 -0800 (PST) Date: Wed, 4 Dec 2024 10:24:41 +0300 From: Dan Carpenter To: Uros Bizjak Cc: x86@kernel.org, linux-sparse@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, Thomas Gleixner , Dennis Zhou , Tejun Heo , Christoph Lameter , Linus Torvalds , Andy Lutomirski , Ingo Molnar , Luc Van Oostenryck , Nadav Amit , Brian Gerst , "H . Peter Anvin" , Peter Zijlstra Subject: Re: [PATCH 0/6] Enable strict percpu address space checks Message-ID: <5b8d0dee-8fb6-45af-ba6c-7f74aff9a4b8@stanley.mountain> References: <20241126172332.112212-1-ubizjak@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241126172332.112212-1-ubizjak@gmail.com> X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: B22D31A0005 X-Stat-Signature: 51a4nqs7krbbpzdisdw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JPhhR8KPLcYGpA5erfN7mRQnEzODE4Mn8OeC2ZO0OU5IDeZBinxT6y9fdVetPKLBQNlRDzyhZvPyTlZbSeBH2opeOvtXlYHFv9oYBdc2lIiuDiQHlcouPd/EnqPgpyGUTajJBumkAj3Yf+sabKXO2DUW5e1gMbY5GksiLp0xYKHUz6stbSncN9MW5LyulUcvQTRHJyRFN2lGgWFo6SUOD4F9zsRp9+XapaGHu9L4iF3ZdTtGTSaHiSymTdOHvZhd7+gCyqzI/QY/Or/Qeswzn6pC3T5ARHlPXcJKEMK6zQpOai5BMMB/X526S36z3az0N9HYwmTogMPCa130r55lteRrgl+6rPIMwi+C3quqpZlZuQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Nov 26, 2024 at 06:21:17PM +0100, Uros Bizjak wrote: > This patchset enables strict percpu address space checks via x86 named > address space qualifiers. Percpu variables are declared in > __seg_gs/__seg_fs named AS and kept named AS qualified until they > are dereferenced via percpu accessor. This approach enables various > compiler checks for cross-namespace variable assignments. > > Please note that current version of sparse doesn't know anything about > __typeof_unqual__() operator. Avoid the usage of __typeof_unqual__() > when sparse checking is active to prevent sparse errors with unknowing > keyword. I don't think it would be super hard to add support to Sparse. The only places where typeof and typeof_unqual are different is that you have to mask away the qualifiers in examine_typeof()? I would take over Sparse maintainership but I'm far too sloppy to do it. We should get Greg to take over, he likes abandoned projects. ;) Signed-off-by: Dan Carpenter --- ast-inspect.c | 1 + ctags.c | 1 + dissect.c | 1 + evaluate.c | 3 ++- parse.c | 24 +++++++++++++++++++++--- show-parse.c | 1 + symbol.c | 17 ++++++++++++++++- symbol.h | 1 + 8 files changed, 44 insertions(+), 5 deletions(-) diff --git a/ast-inspect.c b/ast-inspect.c index b510cd9b1d2c..e940a93a411e 100644 --- a/ast-inspect.c +++ b/ast-inspect.c @@ -110,6 +110,7 @@ static const char *symbol_type_name(enum type type) [SYM_UNION] = "SYM_UNION", [SYM_ENUM] = "SYM_ENUM", [SYM_TYPEOF] = "SYM_TYPEOF", + [SYM_TYPEOF_UNQUAL] = "SYM_TYPEOF_UNQUAL", [SYM_BITFIELD] = "SYM_BITFIELD", [SYM_LABEL] = "SYM_LABEL", [SYM_RESTRICT] = "SYM_RESTRICT", diff --git a/ctags.c b/ctags.c index aa5f9718d847..afdc42b77b98 100644 --- a/ctags.c +++ b/ctags.c @@ -151,6 +151,7 @@ static void examine_symbol(struct symbol *sym) sym->kind = 'e'; case SYM_PTR: case SYM_TYPEOF: + case SYM_TYPEOF_UNQUAL: case SYM_BITFIELD: case SYM_FN: case SYM_ARRAY: diff --git a/dissect.c b/dissect.c index 300d5ca99c97..9419c5931fbb 100644 --- a/dissect.c +++ b/dissect.c @@ -212,6 +212,7 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent) while ((base = node->ctype.base_type) != NULL) switch (base->type) { case SYM_TYPEOF: + case SYM_TYPEOF_UNQUAL: node->ctype.base_type = do_expression(U_VOID, base->initializer); break; diff --git a/evaluate.c b/evaluate.c index fe716f631987..85a6447ba3ce 100644 --- a/evaluate.c +++ b/evaluate.c @@ -358,7 +358,8 @@ static inline int classify_type(struct symbol *type, struct symbol **base) }; if (type->type == SYM_NODE) type = type->ctype.base_type; - if (type->type == SYM_TYPEOF) { + if (type->type == SYM_TYPEOF || + type->type == SYM_TYPEOF_UNQUAL) { type = examine_symbol_type(type); if (type->type == SYM_NODE) type = type->ctype.base_type; diff --git a/parse.c b/parse.c index f868bf63a0f5..95894bf5e54d 100644 --- a/parse.c +++ b/parse.c @@ -54,7 +54,7 @@ static struct token *handle_attributes(struct token *token, struct decl_state *c typedef struct token *declarator_t(struct token *, struct symbol *, struct decl_state *); static declarator_t struct_specifier, union_specifier, enum_specifier, - attribute_specifier, typeof_specifier, + attribute_specifier, typeof_specifier, typeof_unqual_specifier, storage_specifier, thread_specifier; static declarator_t generic_qualifier; static declarator_t autotype_specifier; @@ -196,6 +196,13 @@ static struct symbol_op typeof_op = { .set = Set_S|Set_T, }; +static struct symbol_op typeof_unqual_op = { + .type = KW_SPECIFIER, + .declarator = typeof_unqual_specifier, + .test = Set_Any, + .set = Set_S|Set_T, +}; + static struct symbol_op autotype_op = { .type = KW_SPECIFIER, .declarator = autotype_specifier, @@ -480,6 +487,7 @@ static struct init_keyword { /* Typedef ... */ N("typedef", &typedef_op, .mods = MOD_USERTYPE), A("typeof", &typeof_op), + A("typeof_unqual", &typeof_unqual_op), N("__auto_type", &autotype_op), /* Type qualifiers */ @@ -1052,7 +1060,7 @@ static struct token *enum_specifier(struct token *token, struct symbol *sym, str return ret; } -static struct token *typeof_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) +static struct token *typeof_specifier_helper(struct token *token, struct symbol *sym, struct decl_state *ctx, bool qual) { if (!match_op(token, '(')) { @@ -1065,7 +1073,7 @@ static struct token *typeof_specifier(struct token *token, struct symbol *sym, s ctx->ctype.base_type = sym->ctype.base_type; apply_ctype(token->pos, &ctx->ctype, &sym->ctype); } else { - struct symbol *typeof_sym = alloc_symbol(token->pos, SYM_TYPEOF); + struct symbol *typeof_sym = alloc_symbol(token->pos, qual? SYM_TYPEOF : SYM_TYPEOF_UNQUAL); token = parse_expression(token->next, &typeof_sym->initializer); typeof_sym->endpos = token->pos; @@ -1078,6 +1086,16 @@ static struct token *typeof_specifier(struct token *token, struct symbol *sym, s return expect(token, ')', "after typeof"); } +static struct token *typeof_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) +{ + return typeof_specifier_helper(token, sym, ctx, true); +} + +static struct token *typeof_unqual_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) +{ + return typeof_specifier_helper(token, sym, ctx, false); +} + static struct token *autotype_specifier(struct token *token, struct symbol *sym, struct decl_state *ctx) { ctx->ctype.base_type = &autotype_ctype; diff --git a/show-parse.c b/show-parse.c index e2fc18bb4b3d..ceb6b3cb6f82 100644 --- a/show-parse.c +++ b/show-parse.c @@ -59,6 +59,7 @@ static void do_debug_symbol(struct symbol *sym, int indent) [SYM_UNION] = "unin", [SYM_ENUM] = "enum", [SYM_TYPEOF] = "tpof", + [SYM_TYPEOF_UNQUAL] = "tpof_unqual", [SYM_BITFIELD] = "bitf", [SYM_LABEL] = "labl", [SYM_RESTRICT] = "rstr", diff --git a/symbol.c b/symbol.c index 91352a3a447b..7060acb666d9 100644 --- a/symbol.c +++ b/symbol.c @@ -541,7 +541,7 @@ static struct symbol *examine_pointer_type(struct symbol *sym) return sym; } -static struct symbol *examine_typeof(struct symbol *sym) +static struct symbol *examine_typeof_helper(struct symbol *sym, bool qual) { struct symbol *base = evaluate_expression(sym->initializer); unsigned long mod = 0; @@ -550,6 +550,8 @@ static struct symbol *examine_typeof(struct symbol *sym) base = &bad_ctype; if (base->type == SYM_NODE) { mod |= base->ctype.modifiers & MOD_TYPEOF; + if (!qual) + mod &= ~MOD_QUALIFIER; base = base->ctype.base_type; } if (base->type == SYM_BITFIELD) @@ -560,6 +562,16 @@ static struct symbol *examine_typeof(struct symbol *sym) return examine_node_type(sym); } +static struct symbol *examine_typeof(struct symbol *sym) +{ + return examine_typeof_helper(sym, true); +} + +static struct symbol *examine_typeof_unqual(struct symbol *sym) +{ + return examine_typeof_helper(sym, false); +} + /* * Fill in type size and alignment information for * regular SYM_TYPE things. @@ -595,6 +607,8 @@ struct symbol *examine_symbol_type(struct symbol * sym) return sym; case SYM_TYPEOF: return examine_typeof(sym); + case SYM_TYPEOF_UNQUAL: + return examine_typeof_unqual(sym); case SYM_PREPROCESSOR: sparse_error(sym->pos, "ctype on preprocessor command? (%s)", show_ident(sym->ident)); return NULL; @@ -628,6 +642,7 @@ const char* get_type_name(enum type type) [SYM_UNION] = "union", [SYM_ENUM] = "enum", [SYM_TYPEOF] = "typeof", + [SYM_TYPEOF_UNQUAL] = "typeof_unqual", [SYM_BITFIELD] = "bitfield", [SYM_LABEL] = "label", [SYM_RESTRICT] = "restrict", diff --git a/symbol.h b/symbol.h index 88130c15d4bd..3552d4391621 100644 --- a/symbol.h +++ b/symbol.h @@ -65,6 +65,7 @@ enum type { SYM_UNION, SYM_ENUM, SYM_TYPEOF, + SYM_TYPEOF_UNQUAL, SYM_BITFIELD, SYM_LABEL, SYM_RESTRICT, -- 2.45.2