Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3340470imu; Sun, 11 Nov 2018 12:45:15 -0800 (PST) X-Google-Smtp-Source: AJdET5e+6T6E3fmjg/Xs+FptZwmWEg+DaMnZBGl1Ny2x6fFPK7OjVF/oMC1s7c4ZFS7oegNPRM3i X-Received: by 2002:a17:902:da8:: with SMTP id 37-v6mr17717691plv.12.1541969115166; Sun, 11 Nov 2018 12:45:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541969115; cv=none; d=google.com; s=arc-20160816; b=htheqOING1ownr6eyw1mFan/bNaqx2kS46iyXiJTmo/s3ID1yHi9hovB/ywCqwTRrA ZMvumdXhapIjjohcwZj7aTA9Zp05a7XLCmp0WPGDzcILQYi/oMloa73F8kgXWsKmIzvZ 9yd38HQQ6N1PGStAGDR2KGvZjDGfPFJn4cLLJC2aAfzDBHw6VPIMFBl+Mr6+dvJZFTX5 vwvv8+lr2toA+SDUzIY9uucx8vA+Auw72rixnVVjkM7/nN4C1RhYIPSGkihi0tQTdAbp C7krDsiAuG4w4n3rWCiT4DxnqrWXKJah/n9Ch8/eaXp8y44637J0BKbCXvT2yVDp5Lon yHjw== 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:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=tKOG56ZsASB7FRzm1cGHbzSE38JtQdkrH8mFx1e3Wxg=; b=BK8IEhWLSRbXR7wXgtQx8a+ZGG8llqWsv0/T6cxqtk9fMByvEosyAGNfs9VczV42Q+ PqsuP3b1+y/yHpl3h1CxwQB4kwmJPBkalDcgQn+izK3FAbOsN6Rg6WzBVOuK7M0ZDmlz cK+IjGWRzMNWIUBZhV2j52Q71yja2hU/hvJKFMacEfiEhCBF5HEphgUtalGbhtiBq926 EoZGMqC0EWiuaBBS8LW3tpiyI0d/SdGl/pHOncU2v8iv0hhP/T/mX3XHbaBiK+ia3Qqh LNvLk5h825QmEIQ62bkYXfG4IPOAhFaZuGm9cyusYAltMY3/nlxxcC1zNQIc2BNlYpEp CDOw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 70-v6si17216812pfz.20.2018.11.11.12.45.00; Sun, 11 Nov 2018 12:45:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729871AbeKLGcp (ORCPT + 99 others); Mon, 12 Nov 2018 01:32:45 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49310 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729751AbeKLFsB (ORCPT ); Mon, 12 Nov 2018 00:48:01 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsN-0000l6-Kw; Sun, 11 Nov 2018 19:58:31 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsN-0001MA-Fi; Sun, 11 Nov 2018 19:58:31 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Matthias Kaehlcke" , "Catalin Marinas" , "Will Deacon" , "Mark Rutland" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 002/366] arm64: ensure extension of smp_store_release value In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Mark Rutland commit 994870bead4ab19087a79492400a5478e2906196 upstream. When an inline assembly operand's type is narrower than the register it is allocated to, the least significant bits of the register (up to the operand type's width) are valid, and any other bits are permitted to contain any arbitrary value. This aligns with the AAPCS64 parameter passing rules. Our __smp_store_release() implementation does not account for this, and implicitly assumes that operands have been zero-extended to the width of the type being stored to. Thus, we may store unknown values to memory when the value type is narrower than the pointer type (e.g. when storing a char to a long). This patch fixes the issue by casting the value operand to the same width as the pointer operand in all cases, which ensures that the value is zero-extended as we expect. We use the same union trickery as __smp_load_acquire and {READ,WRITE}_ONCE() to avoid GCC complaining that pointers are potentially cast to narrower width integers in unreachable paths. A whitespace issue at the top of __smp_store_release() is also corrected. No changes are necessary for __smp_load_acquire(). Load instructions implicitly clear any upper bits of the register, and the compiler will only consider the least significant bits of the register as valid regardless. Fixes: 47933ad41a86 ("arch: Introduce smp_load_acquire(), smp_store_release()") Fixes: 878a84d5a8a1 ("arm64: add missing data types in smp_load_acquire/smp_store_release") Acked-by: Will Deacon Signed-off-by: Mark Rutland Cc: Matthias Kaehlcke Signed-off-by: Catalin Marinas [bwh: The same upstream commit was already backported to 3.16, but we didn't have the 1-byte and 2-byte cases then so I dropped that part. Now that we do, pick up that part again.] Signed-off-by: Ben Hutchings --- arch/arm64/include/asm/barrier.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- a/arch/arm64/include/asm/barrier.h +++ b/arch/arm64/include/asm/barrier.h @@ -66,11 +66,15 @@ do { \ switch (sizeof(*p)) { \ case 1: \ asm volatile ("stlrb %w1, %0" \ - : "=Q" (*p) : "r" (v) : "memory"); \ + : "=Q" (*p) \ + : "r" (*(__u8 *)__u.__c) \ + : "memory"); \ break; \ case 2: \ asm volatile ("stlrh %w1, %0" \ - : "=Q" (*p) : "r" (v) : "memory"); \ + : "=Q" (*p) \ + : "r" (*(__u16 *)__u.__c) \ + : "memory"); \ break; \ case 4: \ asm volatile ("stlr %w1, %0" \