Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4422225ybc; Tue, 26 Nov 2019 08:42:10 -0800 (PST) X-Google-Smtp-Source: APXvYqyUSXLN/lbaXsGuNwbjfpDAAGbLYMIoJ0xyHgVwyKSbFYHGgY7leRQJ4bmn2ipadBX52PYq X-Received: by 2002:a17:906:13d0:: with SMTP id g16mr20953647ejc.157.1574786530252; Tue, 26 Nov 2019 08:42:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574786530; cv=none; d=google.com; s=arc-20160816; b=jIu/lZySCDM7ENkZHHE0FdY/YpHiQCNWegC5Pa4fPIwn4yIyb7lnSGYfYEM1zyAWvs j0V8tEudnB7NiwNb543nWL/m4y8+W8ZOAc0Y40giBC2bTstPMH+2Zgpjmv9TCXuaNzgL Lj9CnUoTZob54PSn7V/1R3EdOD+bnrzcy4M3A33w8pHZQPjmBAJ6B0lzrD4ifKaCr+BU pyG6Y2FxkWxn1dZg0vsL4HqSFJgKeNd0UordH/AKzY5JvqOZBPOU0GDovWTnTAc/MRIl o/X75Rwmdvur4vAn80F/RlwQ60tSDLcJTQJ3GnwG9i/SLTbhrCsCWY6q0eDT87bHaQOb E/uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=qdnma+f9GLYVfT3ZkMgoemWBrPr+FJbwRC3ObQWrAI4=; b=zZnkrjhZ0eQgJTWZlOV4CH7B73e6/3J5zRULLB+FqqEAKJMp7ghG9NFu0dwEPfGIxY r2rGZwMPZAnLhebhGKeGrYJ7tl0yUesXawkgXjTNjs4ECTCJMNSwW+LC4RdXZOwpmdYG L2tyCMKZOA/ROFdZqN0Wiu4i0fEHdDnUbWx3Pus+Dw2lO5eoEFINT1IOGyYaPvXdFzBV XZANNmAPft+5RmgoMAfyW5DFYDmnE7ykILFJXr901PXlK0t4VPcd8U+hRoNfcyi8eXYW JQl2aSPgKHgK5ZjnZ1/yzIVU6OxubMX3SGlsrmVVD44iAb6cApVwA81D8iPxe4zHXR3i 3JXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IxyqyGit; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dk13si994899edb.422.2019.11.26.08.41.46; Tue, 26 Nov 2019 08:42:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IxyqyGit; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728501AbfKZQhs (ORCPT + 99 others); Tue, 26 Nov 2019 11:37:48 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45889 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725995AbfKZQhs (ORCPT ); Tue, 26 Nov 2019 11:37:48 -0500 Received: by mail-wr1-f66.google.com with SMTP id z10so23167622wrs.12 for ; Tue, 26 Nov 2019 08:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qdnma+f9GLYVfT3ZkMgoemWBrPr+FJbwRC3ObQWrAI4=; b=IxyqyGit34QSBpbNyeKY4OXYTXtwmPm0MlEXQ+AtQqnMqQYmUGldxV04tJUvsmxGHs UECCcX063oV/1OJz0nyoL5Y1dXFGrl8ighIZzbUg4Q2LZWICWdv8IEZxVBgX+aeAF/RM 9PHgaOAbExOYYtTNm2PxqeA827jv1amNmHvCLqIM1WpOgEnjOQBdbclxveA1moT0fcWX cDjP25GO8Kq5TwYJpnRA/kLWtLabt637TjTjKc4Bv3wSIuxcXrOtQRTshawGJxgS8kbM zyTGakYgMdZOrfYLrgC96loXdT8gjuUv9mBJm57x1pVRKOtlY4eW/rAweKIpZtbxtH1F uCNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qdnma+f9GLYVfT3ZkMgoemWBrPr+FJbwRC3ObQWrAI4=; b=JWnyJl+/VHpX1Rlkb9TLzVg9ZI2qszDP0Ti+Kop7ROOK9J95JCbZo+yZoayDbg42rf 0CWW1uKaKDDI3lYAG7GMa8CsLrbELOPT2TpvJbmaCxygHufm+uacogU7OYUZwi41Tjh3 ReNt8AnGPsvY+rg3dFhgeBQFbTq0LNBwFKclf05olESsk7N+Aa4UihiwWi8hhtJkEIca itUV2t62up+gwuUbCC9LFVFcqWMhS6gdZiVSKl+6KnO+CVEEo3XHkYe+LWNFMejGLv0U epp6VEsj5swl47zMTKUbvaUeB2HxwDjyvOtzI0sDVh7P/9HVk8765V3ltfAD/G9/3Nz9 F0Ow== X-Gm-Message-State: APjAAAWg94iqdjDQ2tw7rs9NWjyhAQFrERVzzo7/mEM5AggXcCELv3sP wUjQn/9CgtwYExG1Wl70res= X-Received: by 2002:a05:6000:104c:: with SMTP id c12mr8582071wrx.212.1574786266079; Tue, 26 Nov 2019 08:37:46 -0800 (PST) Received: from ltop.local ([2a02:a03f:404e:f500:a8f1:829f:a49c:3403]) by smtp.gmail.com with ESMTPSA id m3sm512628wrs.53.2019.11.26.08.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2019 08:37:45 -0800 (PST) Date: Tue, 26 Nov 2019 17:37:43 +0100 From: Luc Van Oostenryck To: Dennis Zhou Cc: Ben Dooks , linux-kernel@lists.codethink.co.uk, Tejun Heo , Christoph Lameter , linux-kernel@vger.kernel.org Subject: Re: [PATCH] percpu: add __percpu to SHIFT_PERCPU_PTR Message-ID: <20191126163743.u4cxecg4chvcvtau@ltop.local> References: <20191015102615.11430-1-ben.dooks@codethink.co.uk> <20191017181301.GA32546@dennisz-mbp.dhcp.thefacebook.com> <20191125224119.GA37611@dennisz-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191125224119.GA37611@dennisz-mbp.dhcp.thefacebook.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 25, 2019 at 05:41:19PM -0500, Dennis Zhou wrote: > On Thu, Oct 17, 2019 at 02:13:01PM -0400, Dennis Zhou wrote: > > On Tue, Oct 15, 2019 at 11:26:15AM +0100, Ben Dooks wrote: > > > The SHIFT_PERCPU_PTR() returns a pointer used by a number > > > of functions that expect the pointer to be __percpu annotated > > > (sparse address space 3). Adding __percpu to this makes the > > > following sparse warnings go away. > > > > > > Note, this then creates the problem the __percup is marked > > > as noderef, which may need removing for some of the internal > > > functions, or to remove other warnings. > > > > > > diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h > > > index a6fabd865211..a49b6c702598 100644 > > > --- a/include/linux/percpu-defs.h > > > +++ b/include/linux/percpu-defs.h > > > @@ -229,7 +229,7 @@ do { \ > > > * pointer value. The weird cast keeps both GCC and sparse happy. > > > */ > > > #define SHIFT_PERCPU_PTR(__p, __offset) \ > > > - RELOC_HIDE((typeof(*(__p)) __kernel __force *)(__p), (__offset)) > > > + RELOC_HIDE((typeof(*(__p)) __kernel __percpu __force *)(__p), (__offset)) > > > > > > #define per_cpu_ptr(ptr, cpu) \ > > > ({ \ > > > -- > > > 2.23.0 > > > > > Hi Ben, > > I've reverted this commit. After spending a little more time on it, I > don't think this is the fix we want because after we call RELOC_HIDE, > we are shifting from __percpu to __kernel address spaces as we're adding > the offset here. I agree. SHIFT_PERCPU_PTR()'s type is as designed. Also, it should be noted that this warning doesn't exist on x86. The problem lies in include/asm-generic/percpu.h, in this case within: #define raw_cpu_generic_add_return(pcp, val) \ ({ \ typeof(&(pcp)) __p = raw_cpu_ptr(&(pcp)); \ \ *__p += val; \ *__p; \ }) There, the variable __p is declared as a __percpu pointer but: 1) the value assigned to it, the return value of raw_cpu_ptr(), is not a plain (__kernel) pointer. 2) the variable is dereferenced just after when a __percpu pointer is implicitly __noderef. It's thus not SHIFT_PERCPU_PTR() or raw_cpu_ptr() that must have their return type changed but the declaration of __p. Here is a quick patch, only compile & sparse tested on mm/vmstat.c: diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h index c2de013b2..757b667ca 100644 --- a/include/asm-generic/percpu.h +++ b/include/asm-generic/percpu.h @@ -74,7 +74,7 @@ do { \ #define raw_cpu_generic_add_return(pcp, val) \ ({ \ - typeof(&(pcp)) __p = raw_cpu_ptr(&(pcp)); \ + typeof(pcp) __kernel __force *__p = raw_cpu_ptr(&(pcp)); \ \ *__p += val; \ *__p; \ Note: the same problem is present in raw_cpu_generic_xchg(), raw_cpu_generic_cmpxchg() & raw_cpu_generic_cmpxchg_double() I need more testing and to evaluate possible side-effects before sending a proper patch. Best regards, -- Luc Van Oostenryck