Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3870878rdg; Wed, 18 Oct 2023 08:18:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnM+dW396WCl4jAtp/uoDhMCbeImfZLw42Q4C+NCBLmDPAJzejfP2aI4Am4xCfVeMdxgK5 X-Received: by 2002:a17:90b:3749:b0:27d:882f:e6c5 with SMTP id ne9-20020a17090b374900b0027d882fe6c5mr5204781pjb.9.1697642301037; Wed, 18 Oct 2023 08:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697642301; cv=none; d=google.com; s=arc-20160816; b=XFRb6inw+FPZGHIEYxF8C7SL59rihPHPNNZNTqmoCDlritJ7cTJrSgCwDKDh+QSXDg WDmpl0xZxCxja/MZvLOd4AcIdE6X9urfxDC/tJCopCYMLqiZP6DGhmy7pG71fhzh05/O ISBjT465gfU4UgAM/XshChCFB0nD4UEmQwbLneXKw6pNN4tQ+ujak8bnrOmVjbBDrobO P4avraTW0xEuHodH58BrMUejQie4WtqEgM7jVMUk0NGOUmO1EmKNZ7d3POd3hjKtrFoY UqLKyknVtCO/5Ve3tIonbyWXjkzH+1HHJpMqMb6I0EUjTBT01HDqGfdnbu6dHilgVCcb QIWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rwmlKg+iurujaoHM78khlFeWHnt3Ry3Unvc1lAlS3ck=; fh=nzKsBgWTayDZeLT+2QeVjDtJqAbCmI+Z4Pl3/plqRts=; b=CETD/JLkNxbieWR5yLCd2w34D6Rcj+FNbo7jZf3q7UpMtOHNdP0XO18Du8uTp8L752 bE+VTuQX5XVbQazzxE6PP+DtSasITdLYMK/mP+0pwqZgebq2nbQ3W1TJJio18hzhcfpw OUIXCXEzhjCSsVi7zlJy+9ZJD7k1KQAemaOjYrwoCI71aX5x7SvWJo7ZmeIbAWXzNzkx H+e2yQLZAD13RLm6J6JBB8vxhzLfBmZ88JCXeFT8yz/Xw3NbxD3QzHISu/m2xvuRDLJS l7SeWLw+zpHcoWU0VGleOroIhkqSkgksN1qbiT2Hhm4IwVc5EgYYVMZWM6y+u0bwm5BO 84QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FjtIrokI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id cx8-20020a17090afd8800b0027d27512cd4si16409pjb.81.2023.10.18.08.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 08:18:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FjtIrokI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6F6B88226F7E; Wed, 18 Oct 2023 08:18:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232311AbjJRPSJ (ORCPT + 99 others); Wed, 18 Oct 2023 11:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbjJRPSH (ORCPT ); Wed, 18 Oct 2023 11:18:07 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE85898 for ; Wed, 18 Oct 2023 08:18:05 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-53e2308198eso11027930a12.1 for ; Wed, 18 Oct 2023 08:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697642284; x=1698247084; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=rwmlKg+iurujaoHM78khlFeWHnt3Ry3Unvc1lAlS3ck=; b=FjtIrokIBwiaJ8LXmwKSw+KVgJj2YP2FU/pcMYQ3vWDmS8lslzPDNqCxsE2hPbKmil /aKAJsgFFLv7Tm73p15ZBZ+eVIh1UwiiRPyAiJpZ182X/gR4oQO6e2XrhNaMEmirL40d n6OpmqVHazRvgiRTZyliYez0qMzIzwKUvED4iu1Wq2ZH+PicGazeRj9SEr9TF43xX66K rcQvmPo6+kYBDXzQaTpKrydnNlCV4S6knrWvjFFJ8Gwyejgfu4+Qf/EchGib9AYSrZ8l 4zgHUbfzVADl21NlJ4Mrp2mM9vMTnkEj75WvW4vQd/N45GTPpaSgcPnK5Kycnr0wh0Y/ TUrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697642284; x=1698247084; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rwmlKg+iurujaoHM78khlFeWHnt3Ry3Unvc1lAlS3ck=; b=H4nmYMrepmI9xCV9E0dMUFg6x2nH6+X/Si+Q2wGLsmbW4qEJCs2ZZ8xJ1acE29FBs7 EpNKHy+RiecEIgK05G8QRj9s1AFgc0cM9O1gwQHm6mckasYRv5MGAYAZ3N93Qo8gCX+C ZvpJcl0z51EOQo7O3RVByiQbRHG+YZL2yeQ1tjLlL/+dz1YnuwqU5mrLpzd9yIAxGawW b9LxSTwWTbwhS/EfRSC+ySSaQgSgyVXF1+LCrCuQj+0w1sbWSZg2WJC0NOxBypXoZfgD HbIS1w+SHVHs6heKljaYTaV+CLQ5d3rcHKPZtBnG8nuishJ+EMfSeApHIJ+Srh680sjb UDRw== X-Gm-Message-State: AOJu0Yy740fjnO++PJDNXrq5kDDjvqCH0WByNNMnaNNJpfF2XSkaNXIJ jXW2/wZ0bthlrpX9jyaNxyftF4A7XUDzYH0FGYM= X-Received: by 2002:a50:8719:0:b0:53e:3732:9aae with SMTP id i25-20020a508719000000b0053e37329aaemr4118128edb.4.1697642283873; Wed, 18 Oct 2023 08:18:03 -0700 (PDT) MIME-Version: 1.0 References: <20231010164234.140750-1-ubizjak@gmail.com> <0617BB2F-D08F-410F-A6EE-4135BB03863C@vmware.com> <7D77A452-E61E-4B8B-B49C-949E1C8E257C@vmware.com> <9F926586-20D9-4979-AB7A-71124BBAABD3@vmware.com> <3F9D776E-AD7E-4814-9E3C-508550AD9287@vmware.com> In-Reply-To: <3F9D776E-AD7E-4814-9E3C-508550AD9287@vmware.com> From: Uros Bizjak Date: Wed, 18 Oct 2023 17:17:51 +0200 Message-ID: Subject: Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr() To: Nadav Amit Cc: Linus Torvalds , "the arch/x86 maintainers" , Linux Kernel Mailing List , Andy Lutomirski , Brian Gerst , Denys Vlasenko , "H . Peter Anvin" , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf , Nick Desaulniers Content-Type: multipart/mixed; boundary="00000000000049b5ec0607ff25d6" X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 18 Oct 2023 08:18:18 -0700 (PDT) --00000000000049b5ec0607ff25d6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Oct 18, 2023 at 4:46=E2=80=AFPM Nadav Amit wrote= : > >> Looks like another case of underspecified functionality where both > >> compilers differ. Luckily, both DTRT when aliases are hidden in > >> another TU. > > > > Attached is the prototype patch that works for me (together with > > Linus' FPU switching patch). > > In general looks good. See some minor issues below. > > > --- a/arch/x86/include/asm/current.h > > +++ b/arch/x86/include/asm/current.h > > @@ -36,10 +36,23 @@ static_assert(sizeof(struct pcpu_hot) =3D=3D 64); > > > > DECLARE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot); > > > > +/* > > + * > > + */ > > Obviously some further comments to clarify why struct pcpu_hot is > defined in percpu-hot.c (the GCC manual says: "It is an error if > the alias target is not defined in the same translation unit as the > alias=E2=80=9D which can be used as part of the explanation.) Sure. > > > +DECLARE_PER_CPU_ALIGNED(const struct pcpu_hot __percpu_seg_override, > > + const_pcpu_hot); > > + > > +#ifdef CONFIG_USE_X86_SEG_SUPPORT > > +static __always_inline struct task_struct *get_current(void) > > +{ > > + return const_pcpu_hot.current_task; > > +} > > +#else > > static __always_inline struct task_struct *get_current(void) > > { > > return this_cpu_read_stable(pcpu_hot.current_task); > > } > > +#endif > > > Please consider using IS_ENABLED() to avoid the ifdef=E2=80=99ry. > > So this would turn to be: > > static __always_inline struct task_struct *get_current(void) > { > if (IS_ENABLED(CONFIG_USE_X86_SEG_SUPPORT)) > return const_pcpu_hot.current_task; > > return this_cpu_read_stable(pcpu_hot.current_task); > } I am more thinking of moving the ifdeffery to percpu.h, something like the attached part of the patch. This would handle all current and future stable percpu variables. Thanks, Uros. --00000000000049b5ec0607ff25d6 Content-Type: text/plain; charset="US-ASCII"; name="p.diff.txt" Content-Disposition: attachment; filename="p.diff.txt" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lnvwcubh0 ZGlmZiAtLWdpdCBhL2FyY2gveDg2L2luY2x1ZGUvYXNtL3BlcmNwdS5oIGIvYXJjaC94ODYvaW5j bHVkZS9hc20vcGVyY3B1LmgKaW5kZXggNTQ3NDY5MDNiOGMzLi42MDdmNmI4ZTE2Y2EgMTAwNjQ0 Ci0tLSBhL2FyY2gveDg2L2luY2x1ZGUvYXNtL3BlcmNwdS5oCisrKyBiL2FyY2gveDg2L2luY2x1 ZGUvYXNtL3BlcmNwdS5oCkBAIC00MTcsNyArNDE3LDYgQEAgZG8gewkJCQkJCQkJCVwKICNkZWZp bmUgdGhpc19jcHVfcmVhZF9zdGFibGVfMihwY3ApCXBlcmNwdV9zdGFibGVfb3AoMiwgIm1vdiIs IHBjcCkKICNkZWZpbmUgdGhpc19jcHVfcmVhZF9zdGFibGVfNChwY3ApCXBlcmNwdV9zdGFibGVf b3AoNCwgIm1vdiIsIHBjcCkKICNkZWZpbmUgdGhpc19jcHVfcmVhZF9zdGFibGVfOChwY3ApCXBl cmNwdV9zdGFibGVfb3AoOCwgIm1vdiIsIHBjcCkKLSNkZWZpbmUgdGhpc19jcHVfcmVhZF9zdGFi bGUocGNwKQlfX3BjcHVfc2l6ZV9jYWxsX3JldHVybih0aGlzX2NwdV9yZWFkX3N0YWJsZV8sIHBj cCkKIAogI2lmZGVmIENPTkZJR19VU0VfWDg2X1NFR19TVVBQT1JUCiAKQEAgLTQ1Myw2ICs0NTIs OCBAQCBkbyB7CQkJCQkJCQkJXAogI2RlZmluZSB0aGlzX2NwdV93cml0ZV84KHBjcCwgdmFsKQlf X3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