Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp9908rdh; Mon, 18 Dec 2023 02:44:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWBlJykGTWqwNPsW8rDWyAcyVvMAJIXoDyZu1UymBgP1xxsDA21VDVyWnVuPvvZRphfauG X-Received: by 2002:a17:903:110e:b0:1d3:1773:8555 with SMTP id n14-20020a170903110e00b001d317738555mr5770893plh.115.1702896274952; Mon, 18 Dec 2023 02:44:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702896274; cv=none; d=google.com; s=arc-20160816; b=DVGamlk32fMy7J5pf5XbAWE8MO//a52LA0CwBTgWTTghQYnwsYxEm+NI9KeqveWwG1 oDVACFxgnPMKBR+Xyyn7WSyTpXZymXId5ZzocVXZUbGIkUKvEqzan8pfeZXnhSRbBUKi GgIoU6Et83CJwQp5FWZvNyynC3F6SfmD3KDog2TiMK9Mlt2WW8YTofrp+TeUMmfEX3Bp mru2ZGlyLRbSaEtm3fzjv32TO2CvTmLky+b1sE5bq0Hqb0YqqLpl4hP86RV18sm4cTnW bf2OATDPKl5fh4XH+a3mtSFyVgJQMU0KboWsP7XuUhKXX0tMslXcVcKD6nFxoyZmIE2m bAfg== ARC-Message-Signature: i=1; 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=h9sAaI5x/m4qa/IsblGkrHPvGq73TiWdoovLssK6KVs=; fh=edP9Vyhdx3wHlRWwndjClkZeqsrAD5QaYzj9PwYQ7RY=; b=NQhW48w6fuiYaHkq9wxoN6rfe3fLgrlkGso1BQ/QX0VhldJ+/aObV51t3iMXogTLA4 GqV01bo+dpG/Y+fF60ASsy3ZO/DE5Ot9RqwGG5jWmqoGZB2nN4YwTskhZ0YHsSHI5pw3 pQpDdt8wt/rXOWlKEwObppI+OZqRcQJ+0vj9tk/XW6xtPNR6rGyqZ5vF6+5F6+56xe9x RjmVzCMxdN2v01n/jLiGGEBBUtCkR9ihsATt8BlVcCtrwjyZ+XuhsDhx3/C9buDz+skC LL0pYiFFmyC/UrXnUBh5j9yanm4Ok+fqZcgHOnMDO5X8DLUfkltSEJ8Dom02HCzOxRFm wszA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nCa27SLn; spf=pass (google.com: domain of linux-kernel+bounces-3355-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3355-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c9-20020a170902d48900b001d3766085a1si6886596plg.564.2023.12.18.02.44.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 02:44:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3355-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nCa27SLn; spf=pass (google.com: domain of linux-kernel+bounces-3355-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3355-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 890032812F2 for ; Mon, 18 Dec 2023 10:44:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D9CA20319; Mon, 18 Dec 2023 10:41:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="nCa27SLn" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (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 39B2E1C2B2 for ; Mon, 18 Dec 2023 10:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5916c6b2e0fso1847788eaf.3 for ; Mon, 18 Dec 2023 02:41:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702896088; x=1703500888; 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=h9sAaI5x/m4qa/IsblGkrHPvGq73TiWdoovLssK6KVs=; b=nCa27SLn2DNBvk+Chcy2MP96Ube2n3Wt2sQ5kgdW2KARzmN+sj3lq0cEaxUpdre86M h7+wU4Thtb4YF/9jMtlBXt3SdOKT1CghRlbwLv5p2/5nC6TyxjL2zH6neFsSIT/Bhjwg hc3I8SLkggHIK+ja53kfQlmxg7hzJkaqw98Zc0cv7E0zme+3H5Q4U3UeX5dYar+aFmkN DWC/U3Z6NW6OuXqxoTIL3gYo86mdWf4s0NUsl72JcBebrsaUCA9yxzsLKy4vGztQ5N2z O6IBQXdG+8gy6g9iYyRMT3Zb+gtjXOTAl6D1XV8IGx5BpY4BOs8afxJzG+gzlfoepxtW 59OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702896088; x=1703500888; 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=h9sAaI5x/m4qa/IsblGkrHPvGq73TiWdoovLssK6KVs=; b=TxkF3ts5sQCFROSxsAyZ2uHqCXsOB8rvdiFKI7J/Qu7GqNKc04Lb5YOROWDLxQFsVH dxjOuHc9+53ZUZBNqC1QkBWY6yEe0XrfsDBQ6CZT19VJe+tWZh3ptWM0lLtdelwJVjkt KuI0ooGXtSOnxLNHqaWB/hBmx1XGbdD3ULesqJ3btF2vt2k0wi2/vMrI9RJXGE/rpYom mpi4aiNRBjsG9e21ybUucW7DiqSkf7cky/CEgpT9/7Ej55zFh/iCBbG57MGh2iLKEmvu avdT9lhcI4ZgMjans753kI29zS+uPCudSgJgvFS8TX+aEg9SLJ5zp2vEAvw1/E1pdpZg QWRw== X-Gm-Message-State: AOJu0YzaYQaMGnN6yBjtpDEzYXBw1jEnO+4k2c5fzpHAEv6FPv1d1MgS pzL3aoPE5zh0cMMVA7pFLBYawwtwm9kh2er6lOg= X-Received: by 2002:a05:6820:168b:b0:58e:1c47:6321 with SMTP id bc11-20020a056820168b00b0058e1c476321mr10764799oob.15.1702896088517; Mon, 18 Dec 2023 02:41:28 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 185-20020a4a1ac2000000b005907ad9f302sm574970oof.37.2023.12.18.02.41.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 02:41:28 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Alexandre Ghiti , Andrew Jones , Anup Patel , Atish Patra , Conor Dooley , Guo Ren , Icenowy Zheng , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paul Walmsley , Will Deacon Subject: [v1 07/10] RISC-V: KVM: No need to exit to the user space if perf event failed Date: Mon, 18 Dec 2023 02:41:04 -0800 Message-Id: <20231218104107.2976925-8-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218104107.2976925-1-atishp@rivosinc.com> References: <20231218104107.2976925-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, we return a linux error code if creating a perf event failed in kvm. That shouldn't be necessary as guest can continue to operate without perf profiling or profiling with firmware counters. Return appropriate SBI error code to indicate that PMU configuration failed. An error message in kvm already describes the reason for failure. Fixes: 0cb74b65d2e5 ("RISC-V: KVM: Implement perf support without sampling") Signed-off-by: Atish Patra --- arch/riscv/kvm/vcpu_pmu.c | 14 +++++++++----- arch/riscv/kvm/vcpu_sbi_pmu.c | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c index 8c44f26e754d..08f561998611 100644 --- a/arch/riscv/kvm/vcpu_pmu.c +++ b/arch/riscv/kvm/vcpu_pmu.c @@ -229,8 +229,9 @@ static int kvm_pmu_validate_counter_mask(struct kvm_pmu *kvpmu, unsigned long ct return 0; } -static int kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, - unsigned long flags, unsigned long eidx, unsigned long evtdata) +static long kvm_pmu_create_perf_event(struct kvm_pmc *pmc, struct perf_event_attr *attr, + unsigned long flags, unsigned long eidx, + unsigned long evtdata) { struct perf_event *event; @@ -455,7 +456,8 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba unsigned long eidx, u64 evtdata, struct kvm_vcpu_sbi_return *retdata) { - int ctr_idx, ret, sbiret = 0; + int ctr_idx, sbiret = 0; + long ret; bool is_fevent; unsigned long event_code; u32 etype = kvm_pmu_get_perf_event_type(eidx); @@ -514,8 +516,10 @@ int kvm_riscv_vcpu_pmu_ctr_cfg_match(struct kvm_vcpu *vcpu, unsigned long ctr_ba kvpmu->fw_event[event_code].started = true; } else { ret = kvm_pmu_create_perf_event(pmc, &attr, flags, eidx, evtdata); - if (ret) - return ret; + if (ret) { + sbiret = SBI_ERR_NOT_SUPPORTED; + goto out; + } } set_bit(ctr_idx, kvpmu->pmc_in_use); diff --git a/arch/riscv/kvm/vcpu_sbi_pmu.c b/arch/riscv/kvm/vcpu_sbi_pmu.c index 7eca72df2cbd..b70179e9e875 100644 --- a/arch/riscv/kvm/vcpu_sbi_pmu.c +++ b/arch/riscv/kvm/vcpu_sbi_pmu.c @@ -42,9 +42,9 @@ static int kvm_sbi_ext_pmu_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, #endif /* * This can fail if perf core framework fails to create an event. - * Forward the error to userspace because it's an error which - * happened within the host kernel. The other option would be - * to convert to an SBI error and forward to the guest. + * No need to forward the error to userspace and exit the guest + * operation can continue without profiling. Forward the + * appropriate SBI error to the guest. */ ret = kvm_riscv_vcpu_pmu_ctr_cfg_match(vcpu, cp->a0, cp->a1, cp->a2, cp->a3, temp, retdata); -- 2.34.1