Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp166594lqb; Tue, 16 Apr 2024 11:49:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJiXy2D01DtDVSqiPkrK1WNJIuW6itOuWlyssZzmFjclKByt6z21NCfWfIq5++eRWXnRmKNKY5F95vBS+DM6D3h3spX4WyXNLeDiLuTg== X-Google-Smtp-Source: AGHT+IHi6RxAR3pCuwjX7aX+Tn3FY6xanUO8m9kFj7i8UcTSx37qNsA45Ju50+5iJpT7TSgHvTCJ X-Received: by 2002:a2e:9b8e:0:b0:2d4:676b:f591 with SMTP id z14-20020a2e9b8e000000b002d4676bf591mr10552102lji.45.1713293356196; Tue, 16 Apr 2024 11:49:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713293356; cv=pass; d=google.com; s=arc-20160816; b=e1wexdI9oNhhCun7bjMfuX7qZCJt/y+p1oQ/GzhIZp3P9EyUOcvlkfiW+8FFNkMrYl XRYv0DBYJ0L7JxQDVqLDw2Ljb9+yhiBUogFuFlPq1YLS4G8Mj1zdjtpMOSpUnzAaMIVS OhhWu7tIM/+TcGpDXT+B2ZmmFT9Jww0AiboapKAVvTKdBiJwog6Lu+7eq7PRkvXB/aWN rGPvgojiF93MxfSF+/7xvgFCN+q4cGkyusFC0YbUQYjnRaaWWolxbCawWgp+u/WxTL5g xoFnXK+qcXoBEDR2Wli9jfgpzgGypCZ142bj2zkhRkE3pOMGOl7v6d07ShnHDHot8mpN 6hGw== 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=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; fh=oaR2Z0fT9ekb3ynL6JoXf+reA2uQ4iXZRJMOGwry+FM=; b=FX0R4D/ZapppH+v4kB6i8MoRhT94X6biOPZux6MaAjMjG0gYE0ctVMBjnzpiJmOYKV FPkFixgP9RsIIlRn8y8fnvBqhkdB2nzOa0VjbSUxdgP3jcpe/8Of3HPb+AvtXG3Ai4+p 7RTf9Y9F1QrZ1idW8bfJAjGCD5qV+KcwtJa7v8HSWsiVjktyx3rnxHj1TV4chLPonAUa G0Vlxnnk+4vzhiyiymnZT52t3zWE5VrXuCT0zjuOVBDsgQE+pmBr9GS14q1fXK5htBAt NJqoBfFMCAMOmXp4Vs4kC23Mhr78oLSNNRfC6E/UndRAy+HPI8BhgYbuK+P27N8Lf9HG MJTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uwv+EDie; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147411-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y89-20020a50bb62000000b0056e6efba980si5894404ede.536.2024.04.16.11.49.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:49:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=uwv+EDie; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147411-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147411-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9BE261F21EFF for ; Tue, 16 Apr 2024 18:49:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7662613C83B; Tue, 16 Apr 2024 18:45:02 +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="uwv+EDie" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 1241A13C3F0 for ; Tue, 16 Apr 2024 18:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293101; cv=none; b=H1Cxa4p3KuExqh8Whc31IMj9sdOxrutbbPNd2rooNnaOLPfuthcuJZYAAILYVJ55b/PGwm7jsMRgei4GRNNxWEjvZal4IyjHHWLr0Dn6ozatyVqjGD1KbBut8LDnNA7hdCV2NiDfAf2Ft4rVrwX0iZpoRCyQTSzd9IO7qlBGTfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293101; c=relaxed/simple; bh=HvWaHaPle0cX5HGWWdRxWlP3z/kNux1E5mFj4+zTNsM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C/xkbaZIGpc/t3yDVn744zArnyWdujzaCAtdFTGQDbotis0OU9097FPq7JIqVXIAXQqI012AoBSExsxDGoiQ/gnDbqR5otm44wNWdBUCnrZ5C/KW97zZYkdGLviIN1P5D8eUDlSxqglYbaEVGnRBoI6rLxRzHpzmnuoAKMM/H2o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=uwv+EDie; arc=none smtp.client-ip=209.85.215.182 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-pg1-f182.google.com with SMTP id 41be03b00d2f7-5dcc4076c13so42418a12.0 for ; Tue, 16 Apr 2024 11:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713293098; x=1713897898; 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=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; b=uwv+EDieKboPbOwWiDwdhRbXg7c0dcf8L1d3kGCh1KQxmNFS3pimdpkt7E3fRK7oHT UQDy1cSjhdO1OnRPJ1WGU1ps0v6K5DigP46KbJjM7iFfKPb0VoV6OBMtkm051d1dTmU4 i48UIXlCtaFM5cEiNT5tPZ7Q+8zPUD02ts+hEiSwWZV7/cG1hh4qji3oWLOjmFwz21vc 1yThUUZpyupoSdF6GPay095r8TrqZ36xiPGrZzFQvjGGdpCEFQW1m8VaIL0+c/kiQLg4 oY90FBElHk6mCclvcNPs777IyBL3fby9f2kyXvSdQenj0WKVX18TTLxjjuhi8IY1o3ly xWnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713293098; x=1713897898; 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=QIyaUvQe1Xat3Gv2wtXts1DoFv5C5UbopqhCGzslRuw=; b=X0/oqlRF6YMCtuqpwYjVSL+Fgelyf/S8h2kwKhgL1JUsrmxbbO+S+ma8iyuznA7vKU qQSTB4SYSbYmPv+ToiaRib8qDGN4K9fxH+YHi++hHaT7ifYKCvHbEiep24vybSUqLyaQ V4/Qj6qd8jaLnG8ZbpWp0JrhZNHpUSx73dh9NlZs2SI9Lx5dAztiGGbO+OsCtFI77QzF xGHIQ1ZKPhnlXOcN3RaJYIdykDTfd9tEgoQCpdPH9QJ9UwYvskUs/k1DnYVn2G5Av3wC AAKIXIA4f2RYzvuzUZ1MFrMQ3X4KT7OhzYPaaLLdqst9lL6kLIrU6tnLGauWNRMlyPpE yyCg== X-Gm-Message-State: AOJu0YwujHrFQVcop0bZ3dBoTS64bOEACCPeol3M0mjtw5o590lVIVS9 iAtaSiViGqdOOapHF9e7WqmoMJE3bp54wr2B2VQoW+C3ioY8eLtfFGFr8UeMknaP4NRQvGkxWsI i X-Received: by 2002:a17:90a:db42:b0:2aa:c389:c9f0 with SMTP id u2-20020a17090adb4200b002aac389c9f0mr2914939pjx.12.1713293098421; Tue, 16 Apr 2024 11:44:58 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o19-20020a17090aac1300b002a269828bb8sm8883645pjq.40.2024.04.16.11.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:44:58 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Ajay Kaher , Albert Ou , Alexandre Ghiti , Andrew Jones , Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, Will Deacon , x86@kernel.org Subject: [PATCH v7 12/24] RISC-V: KVM: No need to exit to the user space if perf event failed Date: Tue, 16 Apr 2024 11:44:09 -0700 Message-Id: <20240416184421.3693802-13-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416184421.3693802-1-atishp@rivosinc.com> References: <20240416184421.3693802-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") Reviewed-by: Anup Patel 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 b5159ce4592d..2d9929bbc2c8 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; @@ -454,7 +455,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); @@ -513,8 +515,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..e1633606c98b 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. + * The 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