From patchwork Wed Jan 31 14:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Parri X-Patchwork-Id: 194815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1962790dyb; Wed, 31 Jan 2024 07:24:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdmf+Y5qZW5SRiVCV7hVLUyU3C6vjj9KWuBIYatN7e2ceIVHBcZibJ9gKxiXE0tgB3OJ8G X-Received: by 2002:a05:6a20:3d01:b0:19c:ad53:2aff with SMTP id y1-20020a056a203d0100b0019cad532affmr5908531pzi.37.1706714643841; Wed, 31 Jan 2024 07:24:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706714643; cv=pass; d=google.com; s=arc-20160816; b=CkDezqNhBM3aSUGPbBrJEmH5qzovdeGA09v4YRpvevxDV8CJ23k3fV79Edc/ckr1Wu 81noSeVBf20T1I0BXCxT7e5GiYbjID7xX5715/ZbBSyTQrF7k0ACWneCACfo7oaCDQXf aY2nQJx+S5kfS6JafZ5qQ94pSesM5u/sVHJtUSsBFk39LRRPjJpdknh4F3765oOnDPcR vnyVqecfkpxvXS6q7RGCt7a5qemicSfcq1fiLOtzX3qt4eQz3W48vMkCaPHyoH8Ttxwk i0E9/F55SA83rlSN3PmUxVE4xQVwhxwc8Itgc9ZN+wzzz+7rDF+4FwqVCLNd3Y3eY1C9 DsPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EgAdMMq2AoWWNilPNigg7Nbpcu7FSjABsk32vurOK/A=; fh=KZNsAVKgPX8aChd53KRR532bwMedHwHEfb9hsZ277bo=; b=kGTvry8fSOZ/ypIYtsClULmtpGLJ5G7Ni4gv77llmOEh34VsO8NH6LrTqqpTgY0qXB KQ1eMjBpBZ2oud4JdV9libpOTpk3N589yq/UE6lSVV21JntPhKV8UqcFdk2tHwjXht/7 admBSSJLmRu0q02MBPKiyUJB16zujYlyEYIeZH4BmgeLhrSPPs19ekabD7rJwHTf4OX1 uLVuXr7hYpP0GailK0ZuuvcHTUBg42tskEVw9+aPy7Q/ZGSR3p80n3kE6JBW8CFsnnjw Gw3anm9rKDqPrctrUHx/iMOBb8Zbq74BnrJ01a8b4wAhuytjUqFrurYlWytRiFXuEQqu Xe+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cAp0dW8N; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-46631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46631-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCVR7DC+pm2iC2+wYdHxgtsT2h17jaEwDZWWVwNpRU2OQdoYpNkTgbW3/8my/sIMoWbqx6acoWGj+APZ0CTkzOLescAXCg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ff22-20020a056a002f5600b006d99584c178si9438636pfb.402.2024.01.31.07.24.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 07:24:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cAp0dW8N; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-46631-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46631-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 00E38B2744C for ; Wed, 31 Jan 2024 14:51:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 460C612AAC4; Wed, 31 Jan 2024 14:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cAp0dW8N" Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FB341272C7; Wed, 31 Jan 2024 14:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706712618; cv=none; b=at8PDNpIQ/ScwcJ5rLtZBMhUlcKumK1dAMkf6VoS/WP7a5xjPNLnOrE+LDykajFlwXcB2QpzCfsyXxGTlBBNL3CKIk834grvDMEYbHxlnO7OiJ6wysbfchoCk1SPcwdD/I7gL0h0SNUVwaAnS0z/SMZVqaQvxZzy973b1sB/xE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706712618; c=relaxed/simple; bh=SaAuQV1IqR4PW259BT1CsorI4rkcdjG7Un7U3Ivx0RY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uEauyvrJDEgoikmH2rDH0x++QyyZW/IudwQjilneStT5dbWG7cKrYnYMu+6VCqZ85A7/GTO3NUfci98/VbRrWs//BZH7RPR/d6cOW1fCoHGrg/hO4UiamVMzn/5yuVvQSMHHqT/ZIHFzmNR7Oetb9IontckCgyu8z/mAyzFYVaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cAp0dW8N; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33ae4205ad8so3013704f8f.2; Wed, 31 Jan 2024 06:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706712614; x=1707317414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EgAdMMq2AoWWNilPNigg7Nbpcu7FSjABsk32vurOK/A=; b=cAp0dW8NgozFlYdh7HnBxhs6EBiDa2ehJA/ilokXAIZ8jGP6LoIggEJikShLzlQdUX wMdYNKgB7Oa/5wjXlNtw6c2JcRQkqUzhJDakrBNglK5nPHb0W6hS6vJpQqB7OC8Av7m0 +QlKPAm03RCiCiOLLAhOj/dODFI0M1IBarkl+cq3Y2G3qHbfACRQOEqXk/n6K6urlBN+ LrNT6zreMLzTaPzZREt+sR755Mbu8UMsjm10vdSH+x7LktQ4UBm5SEPFiEAZDZZ9wd7v uDCLm1Qt6Ik/K7/wQMv989QNDLetxB3jGTIAr+Bg3juc42/VOzs2p8uGSB6sRiBtZcZ+ Cz4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706712614; x=1707317414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EgAdMMq2AoWWNilPNigg7Nbpcu7FSjABsk32vurOK/A=; b=jIuPpIk/lOoEcQZFAI/FRmjMiH2HZBg22P2YAuXsvRsuEYJ1ogwheT84qw3CuH+iix McM1MSH3ebTApdQlVIzimUK62iKrHcRBYslYbLME2llhw4H9Rj5D8vFk+fCVpV/jqKF0 NKTsgBcuUVa4s/34oR88Sz+c+7yMXlN/+3zCvh2N7F4MTNQ/qiBZbN+unBcPgwEF3Ul+ 606/Hr2dRVTBLmJhaUK6jSE7Opo4I0jG88nU5vxl/HG3fYvZIgrzu3RIW+Ue/d9ZRdOZ UnM8Cxli5X9oq7qshDRnoXh3OqkimjZGejm5DVPvFv7EYPWURmyO8HAHH7APd0ePfeic u1+A== X-Gm-Message-State: AOJu0YyhsaYA7LXhRU0vtxHmt3dkBRlxiq7v4VvLvwxW65TdTP2Oub+H yLy8dm8JJagEwtLLunHHzoO4bEejqJCUuT0ai8EACzNjHj+k6dj2 X-Received: by 2002:a5d:64ce:0:b0:33a:e834:5545 with SMTP id f14-20020a5d64ce000000b0033ae8345545mr1675049wri.16.1706712614271; Wed, 31 Jan 2024 06:50:14 -0800 (PST) Received: from andrea.wind3.hub ([31.189.8.91]) by smtp.gmail.com with ESMTPSA id w6-20020a5d4046000000b0033b0d049c71sm419265wrp.54.2024.01.31.06.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 06:50:13 -0800 (PST) From: Andrea Parri To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, mathieu.desnoyers@efficios.com, paulmck@kernel.org, corbet@lwn.net Cc: mmaas@google.com, hboehm@google.com, striker@us.ibm.com, charlie@rivosinc.com, rehn@rivosinc.com, rdunlap@infradead.org, sorear@fastmail.com, linux-riscv@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Andrea Parri Subject: [PATCH v4 3/4] locking: Introduce prepare_sync_core_cmd() Date: Wed, 31 Jan 2024 15:49:35 +0100 Message-Id: <20240131144936.29190-4-parri.andrea@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240131144936.29190-1-parri.andrea@gmail.com> References: <20240131144936.29190-1-parri.andrea@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789620014152651549 X-GMAIL-MSGID: 1789620014152651549 Introduce an architecture function that architectures can use to set up ("prepare") SYNC_CORE commands. The function will be used by RISC-V to update its "deferred icache- flush" data structures (icache_stale_mask). Architectures defining prepare_sync_core_cmd() static inline need to select ARCH_HAS_PREPARE_SYNC_CORE_CMD. Suggested-by: Mathieu Desnoyers Signed-off-by: Andrea Parri Reviewed-by: Mathieu Desnoyers --- include/linux/sync_core.h | 16 +++++++++++++++- init/Kconfig | 3 +++ kernel/sched/membarrier.c | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/sync_core.h b/include/linux/sync_core.h index 013da4b8b3272..67bb9794b8758 100644 --- a/include/linux/sync_core.h +++ b/include/linux/sync_core.h @@ -17,5 +17,19 @@ static inline void sync_core_before_usermode(void) } #endif -#endif /* _LINUX_SYNC_CORE_H */ +#ifdef CONFIG_ARCH_HAS_PREPARE_SYNC_CORE_CMD +#include +#else +/* + * This is a dummy prepare_sync_core_cmd() implementation that can be used on + * all architectures which provide unconditional core serializing instructions + * in switch_mm(). + * If your architecture doesn't provide such core serializing instructions in + * switch_mm(), you may need to write your own functions. + */ +static inline void prepare_sync_core_cmd(struct mm_struct *mm) +{ +} +#endif +#endif /* _LINUX_SYNC_CORE_H */ diff --git a/init/Kconfig b/init/Kconfig index 8d4e836e1b6b1..e2bad47922642 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1982,6 +1982,9 @@ source "kernel/Kconfig.locks" config ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE bool +config ARCH_HAS_PREPARE_SYNC_CORE_CMD + bool + config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE bool diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c index f3d91628d6b8a..6d1f31b3a967b 100644 --- a/kernel/sched/membarrier.c +++ b/kernel/sched/membarrier.c @@ -320,6 +320,7 @@ static int membarrier_private_expedited(int flags, int cpu_id) MEMBARRIER_STATE_PRIVATE_EXPEDITED_SYNC_CORE_READY)) return -EPERM; ipi_func = ipi_sync_core; + prepare_sync_core_cmd(mm); } else if (flags == MEMBARRIER_FLAG_RSEQ) { if (!IS_ENABLED(CONFIG_RSEQ)) return -EINVAL;