Received: by 10.223.185.116 with SMTP id b49csp1183809wrg; Wed, 21 Feb 2018 13:41:48 -0800 (PST) X-Google-Smtp-Source: AH8x2268HhQ8VJnq5iHIvXmgVVS9U1Ly16Q+NC6OKtrx6RQaTczw4wahJh9yr28VNCupH1ZlT1fQ X-Received: by 10.101.73.139 with SMTP id r11mr3837382pgs.322.1519249308654; Wed, 21 Feb 2018 13:41:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519249308; cv=none; d=google.com; s=arc-20160816; b=a6wMPUMV8/rRY60NChZlc3KwsRsKVnEOx0NsisFY3yEz84ocJj5JyxW4JnXMeHJNJY pqILN9TepYsoxkehV1jLbZp6BHnDGtW7Jz4lkjPfG+7X1bdEBLUmbJYEsOA437wK8DAl lIMMDcxvHUcolu8PaW+WOfFEJcVThx72SXB8JygOpWfgJAeOE5Ev9VQ+w6hi++1WbGY7 tZeagnCSsotbmWcW65CuaDI7+damnuE4TKJBMJwSWMPrFF46uwjb3Tfd6pSa5uzm4oMx pFX6zv/ar3KIuCofW4JIXWnQpgAZVivJyRqxYZ9PYL70SdOoQe9zeWrXJi2GPst6/h4h 0Wow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=JWEkeSpqDXDGFYfOJWAOxjeiiJU72renkdlXAxdNvhQ=; b=Clt+BVK4U1D6tcU/3MxMNGHSU87WaGy83hcK4EAh0W9BSOadVxOqUKWKka0EVp3WDw wvg/Mqti2JAUMTh9F6yIYvreTIS0L4BRil9dylkT/w6lTuYpfiUmwbTd3tLjsFuqPICv yQQBFSuJLiCbeDjHCElJSXNx99QBt2OFl1MTFRGAg9GTzo8ClT0k0GTnLzd+3780wVAb 0131UBSylWFzPgitHxGrzcWLFHvafGZLfoDjsLYqQprGLiM5rkdDQanqLV9lan14Q4Bh yTSt8cqBXF5uIPROyoNqxunIpRlYYGNfU3yAjvyO2yY+Sw5QCFLoN66AGPq5W/WdSIgz szwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=tfp7cbax; dkim=fail header.i=@chromium.org header.s=google header.b=hi5B2E3l; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o11si188170pgp.757.2018.02.21.13.41.34; Wed, 21 Feb 2018 13:41:48 -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=fail header.i=@google.com header.s=20161025 header.b=tfp7cbax; dkim=fail header.i=@chromium.org header.s=google header.b=hi5B2E3l; 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=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751378AbeBUVjV (ORCPT + 99 others); Wed, 21 Feb 2018 16:39:21 -0500 Received: from mail-ua0-f194.google.com ([209.85.217.194]:45735 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750779AbeBUVjU (ORCPT ); Wed, 21 Feb 2018 16:39:20 -0500 Received: by mail-ua0-f194.google.com with SMTP id z3so2006676uae.12 for ; Wed, 21 Feb 2018 13:39:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=JWEkeSpqDXDGFYfOJWAOxjeiiJU72renkdlXAxdNvhQ=; b=tfp7cbax9gyQDfqSrWAqGgiYBcvju8mxT+ztJp0bwdPQooOL82CfyH4sAzwSc/gl5q gRO5+zFT6btk+1pueWF4NER9KbGhsI4GGm2v9sBsA2h3OodjkyhiN9teqOCeG2oYKQIM n2tuJrQ5HSWUJXa/SlLiv2iBWzmTCtnhYqZGnXkxz8xhSK+LiSM2OYLxWs/AKwLgL3Nw ewrxl0m91Ixv1rQy0zagrwjTWPU2zynlzt9YLYSKmaGBAM+hR1xiUzUwfVdSkartVol9 y/pZjG3gzbOb52QXn4vs/sKLayMmUg+XXxWmU8SPnfDlcX+molnfBMdvdndByYbZp3qo XtJQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=JWEkeSpqDXDGFYfOJWAOxjeiiJU72renkdlXAxdNvhQ=; b=hi5B2E3lyH1JD+jJBGQahApldnWSsfmAEaj0ATkkoNa9D7R+cUK+sJ54geJj7e6HwD RAazgmjlE8n/nAXUKTn5aQw5aIGx29qCMz47aI70q6LGBLWIuMZnO+xfPBmTjtpGZRVZ ea/G7CKIp7EXizSNEmjfcaSowsJFgBTSa1OZU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=JWEkeSpqDXDGFYfOJWAOxjeiiJU72renkdlXAxdNvhQ=; b=Ul0XOBrmjU2o1g9DVDXTKLJvdcD1RGHPF88pLSbMfYWnJutr/coQWvS3s4y6Zzch7/ XNUdqT7xIi0nkwEAfdMUktvydmUr/poB/2fb+Srj0CBBc4hl6zixxlQhqlhoKAmVwd4O +eBRAuozcQCXaScaZoIK0IT4g1+lQMdKn4F86GordCIN8KdQIWKRjg8ipeL+82kvsHt9 sxc3COkWb30+Xw1khq20ZNGq+MFBfIS61hayqsNVKJZHHj3aIiFMAr5px1PhgYtTCLqI 7nDx0Prb8t9tO3/Jd8SdgpDg3uCecnAWdA/CN+NgbIi1f/+SVMRetQw6nIijdJ3A2Nca FsBA== X-Gm-Message-State: APf1xPBAOE8rO9eYhZMNP3hKWiJuL7yvT8l8RXxVFI11XY61ZEII9F3S /JaCHlVVHguekpneVCNHMy1iDU+33UglpdXLOHZ3Ng== X-Received: by 10.176.93.35 with SMTP id u35mr3634447uaf.74.1519249159036; Wed, 21 Feb 2018 13:39:19 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.242.140 with HTTP; Wed, 21 Feb 2018 13:39:18 -0800 (PST) In-Reply-To: <5A8AF1F802000078001A91E1@prv-mh.provo.novell.com> References: <5A8AF1F802000078001A91E1@prv-mh.provo.novell.com> From: Kees Cook Date: Wed, 21 Feb 2018 13:39:18 -0800 X-Google-Sender-Auth: g3fwGE08kFtiMPgeWQNuDK_OqX8 Message-ID: Subject: Re: [PATCH] x86/asm: improve how GEN_*_SUFFIXED_RMWcc() specify clobbers To: Jan Beulich Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 19, 2018 at 6:49 AM, Jan Beulich wrote: > Commit df3405245a ("x86/asm: Add suffix macro for GEN_*_RMWcc()") > introduced "suffix" RMWcc operations, adding bogus clobber specifiers: > For one, on x86 there's no point explicitly clobbering "cc". In fact, Do you have more details on this? It seems from the GCC clobbers docs[1] that "cc" is needed for asm that changes the flags register. Given the explicit subl and decl being used for these macros, it seems needed to me. > with gcc properly fixed, this results in an overlap being detected by > the compiler between outputs and clobbers. Further more it seems bad Do you mean the flags register is already being included as an implicit clobber because there is an output of any kind? I can't find documentation that says this is true. If anything it looks like it could be "improved" from a full "cc" clobber to an output operand flag, like =@ccs. > practice to me to have clobber specification and use of the clobbered > register(s) disconnected - it should rather be at the invocation place > of that GEN_{UN,BIN}ARY_SUFFIXED_RMWcc() macros that the clobber is > specified which this particular invocation needs. > > Drop the "cc" clobber altogether and move the "cx" one to refcount.h. > > Signed-off-by: Jan Beulich > Cc: Kees Cook > --- > arch/x86/include/asm/refcount.h | 4 ++-- > arch/x86/include/asm/rmwcc.h | 16 ++++++++-------- > 2 files changed, 10 insertions(+), 10 deletions(-) > > --- 4.16-rc2/arch/x86/include/asm/refcount.h > +++ 4.16-rc2-x86-rmwcc-clobbers/arch/x86/include/asm/refcount.h > @@ -67,13 +67,13 @@ static __always_inline __must_check > bool refcount_sub_and_test(unsigned int i, refcount_t *r) > { > GEN_BINARY_SUFFIXED_RMWcc(LOCK_PREFIX "subl", REFCOUNT_CHECK_LT_ZERO, > - r->refs.counter, "er", i, "%0", e); > + r->refs.counter, "er", i, "%0", e, "cx"); > } > > static __always_inline __must_check bool refcount_dec_and_test(refcount_t *r) > { > GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl", REFCOUNT_CHECK_LT_ZERO, > - r->refs.counter, "%0", e); > + r->refs.counter, "%0", e, "cx"); > } > > static __always_inline __must_check > --- 4.16-rc2/arch/x86/include/asm/rmwcc.h > +++ 4.16-rc2-x86-rmwcc-clobbers/arch/x86/include/asm/rmwcc.h > @@ -2,8 +2,7 @@ > #ifndef _ASM_X86_RMWcc > #define _ASM_X86_RMWcc > > -#define __CLOBBERS_MEM "memory" > -#define __CLOBBERS_MEM_CC_CX "memory", "cc", "cx" > +#define __CLOBBERS_MEM(clb...) "memory", ## clb This leaves a trailing comma in the non-cx case. I thought that caused me problems in the past, but maybe that's GCC version-specific? > #if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CC_HAVE_ASM_GOTO) > > @@ -40,18 +39,19 @@ do { \ > #endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */ > > #define GEN_UNARY_RMWcc(op, var, arg0, cc) \ > - __GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM) > + __GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM()) > > -#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc) \ > +#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc, clobbers...)\ > __GEN_RMWcc(op " " arg0 "\n\t" suffix, var, cc, \ > - __CLOBBERS_MEM_CC_CX) > + __CLOBBERS_MEM(clobbers)) > > #define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \ > __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0, var, cc, \ > - __CLOBBERS_MEM, vcon (val)) > + __CLOBBERS_MEM(), vcon (val)) > > -#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc) \ > +#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc, \ > + clobbers...) \ > __GEN_RMWcc(op __BINARY_RMWcc_ARG arg0 "\n\t" suffix, var, cc, \ > - __CLOBBERS_MEM_CC_CX, vcon (val)) > + __CLOBBERS_MEM(clobbers), vcon (val)) > > #endif /* _ASM_X86_RMWcc */ Anyway, I'm fine to clean it up, sure, but I'd like more details on why this doesn't break things. :) Thanks! -Kees [1] https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html -- Kees Cook Pixel Security