Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp955814lqh; Fri, 29 Mar 2024 02:28:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUPshLJewhhHoVbY9X8x1RY4vzbA57dsuSSQ2jDfTzk+SSTy7I0u0hZA9rCAUxeLerODLughtnU8XWGoH0EmLwmsJj3MtWahsiqeYnKQ== X-Google-Smtp-Source: AGHT+IFSxxoPW5ONqMyVsAbkahOOfXOqHgcx2p+1sjrYZUyWJL0HukqMq9J7CHtsqkghsPqhzE7x X-Received: by 2002:a17:906:33d9:b0:a4e:220d:ff21 with SMTP id w25-20020a17090633d900b00a4e220dff21mr1069174eja.59.1711704484191; Fri, 29 Mar 2024 02:28:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711704484; cv=pass; d=google.com; s=arc-20160816; b=LIZ2qN7vv+bnFIjV62yrIj7cKvyeSZKRUgq9tJFZIxq470gCo5hO+rTuAwV7tgazLM KYGwgFHSrESkNuLLfUkKylE+QrNGj4hcTOuDJIVME8itZj7YH1jqGjNgWIcJ6lBT1tSJ WEkI55eTMIDak6QWWWTmrejBSgTkdAIrc5/vfxWkHPElUYBb6r3nPZJKoD6A05Qlfpc2 1UxwKh2RZNjp2WB1E+CcsQeHvF7J56t51eBT+QkVMR4oPTrB0fMm7QKGXboPvbagfJpo kBh4FdX8ryp61WoMq4XJh+29SZqWJmXww+FsKtxc3B0w56d+wxDDCnjKtk4gdlsHSOcX EJoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:from :dkim-signature; bh=wphdEuVRZdcfvU1uZa0UrVCyguVuaKQ82sqpzgvdX+0=; fh=QVoWnvOO+emXpPAV8L6mLaDOlYcGTtUG+s847hYRM1M=; b=J56kghSF2rm6BFQlDMM1rjKR46O3VsrAQGAHFUlkF65E9+/4Df/wAS/nJNz9c7gguQ joM6nqZnug7mv2DirDs2yTke+RBH/dRQkWTm7saXI7rWu5fZHqC+E0ZsWsn6IsvJjxvb jhaK2xe0cIDFJhJQmqcDNIRAZc5hG9QVblPLW8olU7hVepmsfDe2i8Z2QA/pYIJDy/Eg 7c44Itr6jy5hX8Ct0KUzN7G0vF6roJ9IYDm9npx8Z7utVOXZHWX9Vr5rzp+i3tDIn0B8 ascZvmRalfkWiEfTUAWLKLPlwAFEeAUGNwWceyzn2OEpOE0TUAFjkpBTNmoF1RpBgjyH H7JQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=aMUf17tT; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-124332-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124332-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dk16-20020a170907941000b00a4663cc139dsi1698460ejc.795.2024.03.29.02.28.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 02:28:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124332-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=aMUf17tT; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-124332-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124332-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.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 am.mirrors.kernel.org (Postfix) with ESMTPS id BC4091F220D6 for ; Fri, 29 Mar 2024 09:28:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1E58482E9; Fri, 29 Mar 2024 09:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="aMUf17tT" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 3A2204594F for ; Fri, 29 Mar 2024 09:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704462; cv=none; b=EZkYFYcbYLRSaa7du0zaiZQJZ+KghleRXoH6XxLpF2Pzj0SgjlKm2Nuyt2IU+Zu7aAOmxansmA/X6Q/Udc2BEGI1wjHXKrzc5nBBCOgbWlNcnU8MJ8ggsR1CvUYRisD1qAKpUkWFMQVT4rCRx43vdIe08HSK4zPmfTAITgOvBXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704462; c=relaxed/simple; bh=5ACZJa3Tq3dvPUxK1QZqVzKwAxpacncCtJOs3+hxanM=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=tqstYW2iBljhISHk0edujKOPn2y2b5Ocfd51tC1cxqlZD7RE3KQPEyc5ASqmRG40WT0N2TSmU4QIIVdr+TuUnfuDSBnADexcDXPzFqX863jxDpEgiYMCX5U7Z+sWRTit+SJ+S9B+V5Kj5BKZnRQR97ThWnmKzKOuJPd5oK4Sz9I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=aMUf17tT; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1e0f0398553so17449235ad.3 for ; Fri, 29 Mar 2024 02:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711704460; x=1712309260; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=wphdEuVRZdcfvU1uZa0UrVCyguVuaKQ82sqpzgvdX+0=; b=aMUf17tTpTNeG7DergaquCVpR+cZU7zIOULs2Ggzraeb1Y2NMbNJnPfhCLrpDCxUzN xIFjDc/kWvL+NSzp/6z0GpXaWpG+IO+LLay3VbHY4egNxMxfSDeGxAtUlZiSMxD8GYJc Vu/GFvoLEEPq7V4AlCIb+H3dsK2/oOVDlzU8eWQKJHP/+xe+ZoZYuzZwSb7v4cC+rClh Q+7sRAMLW71q2YZLSxsEFCFRDFL5eAWeK+CI7m+0ZFV2nCQXVnCDuqlJHhKHGa3bAqrT Kn9occ+rCWkAvOggGVEt7G8FkLlnZmck1QpDj9n07TnNUBo5BozKzjW3T68hVv44hshV Z6UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711704460; x=1712309260; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wphdEuVRZdcfvU1uZa0UrVCyguVuaKQ82sqpzgvdX+0=; b=evDbD0uGA+OvmeHPnX5PcsHLFuat6CAV0rPez9gF9tK/8YQjW9ldNjpsTf/JmFSMw1 oOb40AsXDUXJDePiG7Zk7HMVE7UPnUgt8kuhjZg3/EuOpZyDSlDpRUJ3izghGBn9iIDR dFRV9L91GOmjdTv5AX9DUn4rf5Hr9K/GVVLVqOAG6WBHqziVqISwoujohHu9+DQGCBmd 9sYzq08wC7sI7yDJHfYa0oOkWkVA32Z+YnJhIcIvn+SirAN5yvr7DeqFDbC6ZkhVv3Ub AwCyngnOA+x4wWFWx/L/5t67rd3acTQ1q0OgPmJa2XKAz1jwpUpakF5pA6TOVHeq/ciq 6C1w== X-Forwarded-Encrypted: i=1; AJvYcCV3KZ0+WxGd/reYYNqVjfUrZhy4wenbyM3Wj2NYG9HM+18yp/c6fJcWLgMFrB7jhv4ftsymzDhHVWVXwkaYNSijkLwPv9iv40/h4NTG X-Gm-Message-State: AOJu0Yy2X/8jtE4EoZbjp0Jd7fdCRZTVndnF1eCgOVslKrqB/kZq3O18 CvGrjpk4ibqK3he0xjm+E7CajNZmwLTcE2y28ndvMQersQoLhaoPtc6QTaHtX/8= X-Received: by 2002:a17:90a:4216:b0:2a0:33c2:997e with SMTP id o22-20020a17090a421600b002a033c2997emr1713230pjg.41.1711704460537; Fri, 29 Mar 2024 02:27:40 -0700 (PDT) Received: from [127.0.1.1] (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id cv17-20020a17090afd1100b002a02f8d350fsm2628830pjb.53.2024.03.29.02.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 02:27:40 -0700 (PDT) From: Max Hsu Subject: [PATCH RFC 00/11] riscv: support Sdtrig extension hcontext/scontext CSRs Date: Fri, 29 Mar 2024 17:26:16 +0800 Message-Id: <20240329-dev-maxh-lin-452-6-9-v1-0-1534f93b94a7@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIADmJBmYC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDYyNL3ZTUMt3cxIoM3ZzMPF0TUyNdM11L3WQzIwPLVLOUJDPzNCWg1oK i1LTMCrCx0UpBbs5KsbW1ABEr0dRrAAAA To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J. Wysocki" , Pavel Machek , Anup Patel , Atish Patra , Paolo Bonzini , Shuah Khan Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, Max Hsu , Nick Hu , Yong-Xuan Wang X-Mailer: b4 0.13.0 riscv-debug-spec [1] Chapter 5: Sdtrig extension introduces trigger CSRs which can cause a breakpoint exception, entry into Debug Mode, or a trace action without having to execute a special instruction. The focus in the following patches is on the two CSRs from the Sdtrig extension: hcontext and scontext. These two CSRs are optional according to the spec, apart from the Smstateen extension [2], which has bit 57 to control the accessbility of the hcontext/scontext CSRs. We also introduce dt-binding in the CPU DTS for the existence of the CSRs in situations where the Smstaten extension is not available. The hcontext/scontext CSRs can help to raise triggers with the textra32/textra64 CSRs set up correctly. (Chapter 5.7.17/ 5.7.18 [1]) Therefore, as part of Linux awareness debugging. We propose the scontext CSR be filled by the Linux PID, And the hcontext CSR be filled with a self-maintained Guest OS ID. The reason for using the self-maintained Guest OS ID instead of VMID is that VMID might change over time, and the user setting up the trigger might enter the previous value, invoking the wrong VM for debugging. The tests have been done on QEMU with Sdtrig CSRs (mcontext/hcontext/scontext implemented) [3] boot on virt machine and also run the Guest OS as virt machine with KVM enabled, the two hcontext/scontext CSRs can be written correctly. This patch series is based on v6.9-rc1. Link: https://github.com/riscv/riscv-debug-spec/releases/download/ar20231208/riscv-debug-stable.pdf [1] Link: https://github.com/riscvarchive/riscv-state-enable/releases/download/v1.0.0/Smstateen.pdf [2] Link: https://github.com/sifive/qemu/tree/dev/maxh/sdtrig_ISA [3] Signed-off-by: Max Hsu --- Max Hsu (7): dt-bindings: riscv: Add Sdtrig ISA extension dt-bindings: riscv: Add Sdtrig optional CSRs existence on DT riscv: Add ISA extension parsing for Sdtrig riscv: Add Sdtrig CSRs definition, Smstateen bit to access Sdtrig CSRs riscv: cpufeature: Add Sdtrig optional CSRs checks riscv: suspend: add Smstateen CSRs save/restore riscv: Add task switch support for scontext CSR Yong-Xuan Wang (4): riscv: KVM: Add Sdtrig Extension Support for Guest/VM riscv: KVM: Add scontext to ONE_REG riscv: KVM: Add hcontext support KVM: riscv: selftests: Add Sdtrig Extension to get-reg-list test Documentation/devicetree/bindings/riscv/cpus.yaml | 18 +++ .../devicetree/bindings/riscv/extensions.yaml | 7 + arch/riscv/include/asm/csr.h | 6 + arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/kvm_host.h | 14 ++ arch/riscv/include/asm/kvm_vcpu_debug.h | 24 +++ arch/riscv/include/asm/suspend.h | 7 + arch/riscv/include/asm/switch_to.h | 15 ++ arch/riscv/include/uapi/asm/kvm.h | 9 ++ arch/riscv/kernel/cpufeature.c | 162 +++++++++++++++++++++ arch/riscv/kernel/suspend.c | 25 ++++ arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/main.c | 4 + arch/riscv/kvm/vcpu.c | 8 + arch/riscv/kvm/vcpu_debug.c | 107 ++++++++++++++ arch/riscv/kvm/vcpu_onereg.c | 63 +++++++- arch/riscv/kvm/vm.c | 4 + tools/testing/selftests/kvm/riscv/get-reg-list.c | 27 ++++ 18 files changed, 500 insertions(+), 2 deletions(-) --- base-commit: 317c7bc0ef035d8ebfc3e55c5dde0566fd5fb171 change-id: 20240329-dev-maxh-lin-452-6-9-c6209e6db67f Best regards, -- Max Hsu