From patchwork Thu Oct 24 12:47:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 177431 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp2142008ill; Thu, 24 Oct 2019 05:49:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOFaxFgZFy0NCCHUv7hjA+NBR2i518cFk9H++NKkTcMqgTs4UWFZFC5UuupbFCk1GwL6E0 X-Received: by 2002:a17:906:e8d:: with SMTP id p13mr37600177ejf.236.1571921344146; Thu, 24 Oct 2019 05:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571921344; cv=none; d=google.com; s=arc-20160816; b=MluM5bdcCWVNhoDkH7nKuKkhLKPz6NJuBf05XsrwYX8nF3gUeMuFBTPDqweMflYPG2 Ph2LirBLj8gzgylrpPRS6rVIiM9cIJCc+GExA6dOhZeKvX2JlP5rpgw/1+C3qumxhP4a B/kDS+hfu38QhC2CkIKLgogYNa7JX1DYmZgRUVOrEwqz7rICuBptKiFI7ETPM4yWVW+V OPK9EL53bMBAZMQgZWhS04ySNSKcQn1NxNFC7v3OORq06XZL+x9GYwvC1iPjOcduqcZk 05kixnj7v9+NhKujZFOjw8z40IId3HMX+ALfUliQ7nWS9dXrGo0jASCL5EL6TE5bO7Yz EMGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FGLorEesDsfAmxFmFpT9rKaAuqHDIZiwQnvART+qIuc=; b=Qj3PH7ZOC4NqKF5yk025UtiLL2RaZ4WWjlmRdQ6iq54tqdA5yLSWsM7Mg0Lsmy5L5D unzdvEEro+unSwK+M7sk69eu6bso1HFLOpG9O1cdRH4WxkN3CdpRkFpCyz0TONiZ5Oh+ 3N1ONdK3JcQ49TeUVmunq+s5H//IS1SUwgv5dQwA75hArLkqpjXIkE99yw1JIIGeaxOQ f2UwSU8N24T94jv9eVnlyGfGPvCvPZpqDor3JlO04L35vHRdnZGe9NDZSgvbMdeDqa1B TBsFrocaOM68OS5HAOhCs7isCXwOXgxsWkXUKa9j0Cjra2CG573E60pcH5/22+xJMQmo AsRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MXhIjmhc; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si12973378eda.251.2019.10.24.05.49.03; Thu, 24 Oct 2019 05:49:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@linaro.org header.s=google header.b=MXhIjmhc; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728342AbfJXMtD (ORCPT + 14 others); Thu, 24 Oct 2019 08:49:03 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33087 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727913AbfJXMtD (ORCPT ); Thu, 24 Oct 2019 08:49:03 -0400 Received: by mail-wr1-f66.google.com with SMTP id s1so17173382wro.0 for ; Thu, 24 Oct 2019 05:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FGLorEesDsfAmxFmFpT9rKaAuqHDIZiwQnvART+qIuc=; b=MXhIjmhcLgKtMpSxfoK4lgqDGGGPPMeIXzPvfIklgcEiN1VW0+wWD0Nmsc12sy4rvW GtH3Y/nSZQ0MYWQedpRU07eBaivkLHkgvLJnwQYGTdMzSSGiIsKUY/HBT/GVEnsRQ5Lv fxoknWwwuFN1jjkRIy2LIG7qEerbISYAfGyC4vvPs1wl4Y7qlA5Le5ap2vCjNl+g/g8Y 5oeHwPyjBmeEyFB8EOZDaktDzha0+o2fFVr+H+LIb/Klr3/ndgpCnz2BGOM9y8XvbZo8 8htrYg+UWhh+TjhxX82u8vZvWo60iRj3P/66ZOfywVcSjtHWW0POPWlBbr9prlP2R9UA U7LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FGLorEesDsfAmxFmFpT9rKaAuqHDIZiwQnvART+qIuc=; b=sO9DVtkc4XzOr3i8dQxboSXvJx8640LiB64fdcM8/jwWWxs5MT8+vsBGwjOGSvlo7+ 4AalS0MiXOmAUEzLJLgsZN1gkyMCpIbnWOORlahTvlKv/B8lWGzOQXMg01jxLXr5+0gB Uc4HCiNJ9VwFX3FLr/tqOhXmAqptVImUqo/m/tuBrNVEkk0MViP/hFBV+LX3QVk9ZIw4 xoKTuSxtVGq7zPqvdby6OvgNxmebucpBoKdZ5y+UNzCsrMq49Ep2ZwEvDCjj6Pj+lS61 mtkEaFIDsKlLwFEgTvVgjymTDEr1DnMYGKYuz+EfNR+7XFJVQ1B6pixJixoyChaq+vh9 SWfA== X-Gm-Message-State: APjAAAUv+cOBvBj+SFv3/y/FN8noObdvtxvMKCWWboh1iX8ac+qfSftG RIg5V1mc45xMunFTxOy4/nsvL7TKDaNc6tzJ X-Received: by 2002:a5d:678e:: with SMTP id v14mr3573451wru.393.1571921341138; Thu, 24 Oct 2019 05:49:01 -0700 (PDT) Received: from localhost.localdomain (aaubervilliers-681-1-126-126.w90-88.abo.wanadoo.fr. [90.88.7.126]) by smtp.gmail.com with ESMTPSA id j22sm29111038wrd.41.2019.10.24.05.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 05:49:00 -0700 (PDT) From: Ard Biesheuvel To: stable@vger.kernel.org Cc: Ard Biesheuvel , Will Deacon , Catalin Marinas , Marc Zyngier , Mark Rutland , Suzuki K Poulose , Jeremy Linton , Andre Przywara , Alexandru Elisei , Dave Martin , Marc Zyngier Subject: [PATCH for-stable-4.14 09/48] arm64: Introduce sysreg_clear_set() Date: Thu, 24 Oct 2019 14:47:54 +0200 Message-Id: <20191024124833.4158-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191024124833.4158-1-ard.biesheuvel@linaro.org> References: <20191024124833.4158-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mark Rutland [ Upstream commit 6ebdf4db8fa564a150f46d32178af0873eb5abbb ] Currently we have a couple of helpers to manipulate bits in particular sysregs: * config_sctlr_el1(u32 clear, u32 set) * change_cpacr(u64 val, u64 mask) The parameters of these differ in naming convention, order, and size, which is unfortunate. They also differ slightly in behaviour, as change_cpacr() skips the sysreg write if the bits are unchanged, which is a useful optimization when sysreg writes are expensive. Before we gain yet another sysreg manipulation function, let's unify these with a common helper, providing a consistent order for clear/set operands, and the write skipping behaviour from change_cpacr(). Code will be migrated to the new helper in subsequent patches. Signed-off-by: Mark Rutland Reviewed-by: Dave Martin Acked-by: Catalin Marinas Signed-off-by: Marc Zyngier Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/sysreg.h | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.20.1 diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index f0ce6ea6c6d8..5f391630d0f4 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -584,6 +584,17 @@ asm( asm volatile("msr_s " __stringify(r) ", %x0" : : "rZ" (__val)); \ } while (0) +/* + * Modify bits in a sysreg. Bits in the clear mask are zeroed, then bits in the + * set mask are set. Other bits are left as-is. + */ +#define sysreg_clear_set(sysreg, clear, set) do { \ + u64 __scs_val = read_sysreg(sysreg); \ + u64 __scs_new = (__scs_val & ~(u64)(clear)) | (set); \ + if (__scs_new != __scs_val) \ + write_sysreg(__scs_new, sysreg); \ +} while (0) + static inline void config_sctlr_el1(u32 clear, u32 set) { u32 val;