From patchwork Wed Sep 11 12:33:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA66BEE499F for ; Wed, 11 Sep 2024 12:37:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMXq-0004ic-6u; Wed, 11 Sep 2024 08:34:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXh-000445-TG for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:33:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXf-00010y-Qp for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:33:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YabOEkQqVQQuj2asf79OGJROe40H9cY/9FGkA84yObA=; b=B9cvOfIjD9SDyZTJRhYZmIXISngUYDCl5TtwC5iiGVF8mKjLzWpXYZE+O4vPzi79FUHGuY GLaKU14yuz9m85fuDKQqArjVEh5WUDsYCG5tpm3YlQlZz/59Z2Feb5kz7xxkX4urBzZcsw pw6AFHtgBti+bWJoyHWQ8DmnDCym4ag= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-LsMHo-U-NXmYxS-ZPFln5g-1; Wed, 11 Sep 2024 08:33:50 -0400 X-MC-Unique: LsMHo-U-NXmYxS-ZPFln5g-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42cb0b0514bso35245495e9.1 for ; Wed, 11 Sep 2024 05:33:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058029; x=1726662829; 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=YabOEkQqVQQuj2asf79OGJROe40H9cY/9FGkA84yObA=; b=SEywijbqTRb7iwlS4yDyvK2xG9K2bDRXu1pLV5Y+irHoeyKwW3ykOOxdilXAXBJfm7 DfUZw8HyVCJC8hJU/mmrpecJf6+afS8bpsADHpkUjvDwYnKiqBEcTB6MQ5T23CWtawa5 s2aST3B528wG8C5+hs6Qu6pjrhlNhYaJQ1YtNu2J7Of07g9IdBFqEmb07fWsmJ6SLK0F MzR65XOpJK7ybUS1n1AnWzcGlnNBJ39We0pHH39+pzoKp35HIDOhII/vUq+kMA7tjR4i MiCN3CNh+oCR+fvfH4Lc24RsIDB4HpgVzakjP+cRviZoS7xL1fM3kKaeGdzT10p26x/Q zgTQ== X-Gm-Message-State: AOJu0YwoNg7RFXOOFIOZin3P1tGp9cp1GugkBxkW8S2Fwi1rJ/E4nRXE IQqWEsBWdBbsHpAo3SGzHStTfM2Hn0tPif8ETmYmsXx0h9OpyrfjlX6f6VNgEzH/Me6l98GbcKw jCJEmv1YemhAUno7b/DY7YGcbWPa2igeIlKHzw1MXniY20+SGxwQarOBeDubtKXdSIlcU9e9qoV 0IaTyz40Ii9hw3Ii0+z2a5zg2VCFqOUNQ03S2MF7s= X-Received: by 2002:a05:600c:3ca7:b0:428:f0c2:ef4a with SMTP id 5b1f17b1804b1-42c9f97caa0mr145663945e9.13.1726058028714; Wed, 11 Sep 2024 05:33:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwHapi49LVjQ6ULmf4m4xN9cQnqUC9pfVNF8z96TFwaRrhUiNRrY4qaNwdnuAHV92T0acePQ== X-Received: by 2002:a05:600c:3ca7:b0:428:f0c2:ef4a with SMTP id 5b1f17b1804b1-42c9f97caa0mr145663695e9.13.1726058028130; Wed, 11 Sep 2024 05:33:48 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb2f86488sm124715065e9.15.2024.09.11.05.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:33:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: "Xin Li (Intel)" Subject: [PULL 01/17] target/i386: Delete duplicated macro definition CR4_FRED_MASK Date: Wed, 11 Sep 2024 14:33:26 +0200 Message-ID: <20240911123342.339482-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Xin Li (Intel)" Macro CR4_FRED_MASK is defined twice, delete one. Signed-off-by: Xin Li (Intel) Link: https://lore.kernel.org/r/20240807081813.735158-2-xin@zytor.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 14edd57a37b..2bf37dd15e0 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -267,12 +267,6 @@ typedef enum X86Seg { #define CR4_FRED_MASK 0 #endif -#ifdef TARGET_X86_64 -#define CR4_FRED_MASK (1ULL << 32) -#else -#define CR4_FRED_MASK 0 -#endif - #define CR4_RESERVED_MASK \ (~(target_ulong)(CR4_VME_MASK | CR4_PVI_MASK | CR4_TSD_MASK \ | CR4_DE_MASK | CR4_PSE_MASK | CR4_PAE_MASK \ From patchwork Wed Sep 11 12:33:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800458 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD855EE499F for ; Wed, 11 Sep 2024 12:34:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMXu-00058W-Eu; Wed, 11 Sep 2024 08:34:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXl-0004Iw-7O for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:33:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXj-00011M-Jp for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:33:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1CNOQq4FCPyKHD3scgo6SQA3bN8P0n+b7XCCMQAnvYU=; b=Wp8BFSMmiSWKFtN44VrVDNFw981lsWn+2WjlkHYXrWrRNKm9jQVn3VFN7BA1e4GIirZP3X iC09n9qpR3TDaEwPg/+JtGO5sFV/kxKZ78Pzf1Lr5gUr680idZFe/b1xE8hC1beyz8Qm4j HyJ72LdjUkrKTJHmHX+Gc8AIJxlFtP4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-5-2hB0P5OkmnxVKNCfqKxQ-1; Wed, 11 Sep 2024 08:33:53 -0400 X-MC-Unique: 5-2hB0P5OkmnxVKNCfqKxQ-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-42cb940cd67so28460725e9.0 for ; Wed, 11 Sep 2024 05:33:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058031; x=1726662831; 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=1CNOQq4FCPyKHD3scgo6SQA3bN8P0n+b7XCCMQAnvYU=; b=wfhILvHQy9IMP4z+LnBG/iwucocASghTEEiOqB2Z1mTy59eC6d8qcAaEgP2z+fuUKc kzjVocb7LzS2DCif7iXcJBb3EKhYTsd7HY1eg11I8SuOCWyppiU6oVt65FJi2Q+PAYcJ 3oWwDZ7xaQChlcHvBVEyzlyXDwgmF3gGKqFLKNaZSL73hxYjDcJ953+04UtbGUZhTtKY qDd/jTyFx3Kh1v1FF0u42qOTCejS5qiuBfMwIp3MD2OFe2kwe+WhFbVXKVLNvnVdbGgE 8GBf4saz+/I1gSsIF8w9ZKfDroFMjPEKSaUZxlToxuAu8sPlHAzGUOZ2gkWcSnehjbjD L7IA== X-Gm-Message-State: AOJu0Yyue+5O+dsklaR7qIvkCyrJfVD3zibEfPJbePN5UOqEKoJr2BCF VgfJ7i7pDpBDcITdu8fxBDaRWwQ8xRxIVPvsWMkooFBD3f0rB1dhlY+P3Dl1S5PWA28XzxXKo10 jgiCj679GcF2X9I/qE0q4NBnYcO6pWXpudU+1GG8C5vSb9FGa9G03o9LatqWK8DUgVQSiBkw2P0 c9Bia5ueen9qzcE0s6Y30jYQPR/1r0FZuUfd4+rmc= X-Received: by 2002:a05:600c:1396:b0:426:6e9a:7a1e with SMTP id 5b1f17b1804b1-42c9fa0b8b2mr146490905e9.35.1726058031197; Wed, 11 Sep 2024 05:33:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKOy9OyfO/IWkYn4OlDbzv0wUQp1YhEDUA+b/Z9yzbuZtiMulZ0zLPPkZVgb74xCktmw3Jbg== X-Received: by 2002:a05:600c:1396:b0:426:6e9a:7a1e with SMTP id 5b1f17b1804b1-42c9fa0b8b2mr146490655e9.35.1726058030697; Wed, 11 Sep 2024 05:33:50 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42caeb30b83sm141316825e9.14.2024.09.11.05.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:33:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: "Xin Li (Intel)" , Zhao Liu Subject: [PULL 02/17] target/i386: Add VMX control bits for nested FRED support Date: Wed, 11 Sep 2024 14:33:27 +0200 Message-ID: <20240911123342.339482-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: "Xin Li (Intel)" Add definitions of 1) VM-exit activate secondary controls bit 2) VM-entry load FRED bit which are required to enable nested FRED. Reviewed-by: Zhao Liu Signed-off-by: Xin Li (Intel) Link: https://lore.kernel.org/r/20240807081813.735158-3-xin@zytor.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 85ef7452c04..31f287cae05 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1435,7 +1435,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { "vmx-exit-save-efer", "vmx-exit-load-efer", "vmx-exit-save-preemption-timer", "vmx-exit-clear-bndcfgs", NULL, "vmx-exit-clear-rtit-ctl", NULL, NULL, - NULL, "vmx-exit-load-pkrs", NULL, NULL, + NULL, "vmx-exit-load-pkrs", NULL, "vmx-exit-secondary-ctls", }, .msr = { .index = MSR_IA32_VMX_TRUE_EXIT_CTLS, @@ -1450,7 +1450,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { NULL, "vmx-entry-ia32e-mode", NULL, NULL, NULL, "vmx-entry-load-perf-global-ctrl", "vmx-entry-load-pat", "vmx-entry-load-efer", "vmx-entry-load-bndcfgs", NULL, "vmx-entry-load-rtit-ctl", NULL, - NULL, NULL, "vmx-entry-load-pkrs", NULL, + NULL, NULL, "vmx-entry-load-pkrs", "vmx-entry-load-fred", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, From patchwork Wed Sep 11 12:33:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BEE4FEE49A1 for ; Wed, 11 Sep 2024 12:34:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMXs-0004wV-FA; Wed, 11 Sep 2024 08:34:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXo-0004Zc-Ej for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXl-00011w-Ud for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C/bQlCWHRUXU1TzSq1fa/WJJq3aN/po0ArhGdFaRGLw=; b=S0XrpTuT3OZjPuqU7ax4W0lMs9v01HOO7slMXyWpiJOTOmQIGqErBBzPtDHQiAJ42Li7rO p2oRGyYAbLdx/B+Hu4cfXFyPjajCNM95x5bQyOBHZQs0tKeAEyc8Up7aLLshsb919LE3Ck 6nk7TtE+CSLzEzfQ65+9npc9n580yx8= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-LlSaepYHOo-j9zdcuSFMrg-1; Wed, 11 Sep 2024 08:33:55 -0400 X-MC-Unique: LlSaepYHOo-j9zdcuSFMrg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-374bb2f100fso2896713f8f.0 for ; Wed, 11 Sep 2024 05:33:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058034; x=1726662834; 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=C/bQlCWHRUXU1TzSq1fa/WJJq3aN/po0ArhGdFaRGLw=; b=WePwxSMdMg7xHvoFAWlgeEIatBixMwmBPWLvJ3IoIWZcgvTk56f9vG8NPb4O+ZLUzd RK/4PMGhQzp4fkgyVGDRUlYC9KxJe/tLioNMkVdz+HY2nTx6BDIxdYM05zRjXZQFRVtn luTUKgX3jtPa45ZhJ/rKXZXYgthgScsCuIQPYreSAryE25/NUs0qhDr+UPuVIqxDiAyn Xi1EKtFQuozmEM8s8TBka1XA4XmgDG0he5GYrw0N9ZZNJBH/Vj0mIxLbYTw0yYsBQyFD nuh19vEt2mepGR0sZGbSsRdeC4P5cO0GzKOP9NO236cGKCnvjjFOzUJ2tqPKADyMKWNX DADA== X-Gm-Message-State: AOJu0YxswO1uxUQEZmGnyc+Z/AuHjhC5ZfH2RYHoRya2kou8HZNjoICw LgVMVYkZluTN856GJPhbbkzkMqr93/dHaW7lwvfgBoLEDv1R7oyufpnYTjLyGoLEyhKXOVx2k/4 /5zgyDZz22yQGHem6lUIp+MeziPHRIoM8gYN60aPCXw0yjCEcJhaDQSFYk6s0ilYJOE+3aCc3Du ufS2EwBr2Xza49RoJ74AjfLCEQaOp6piTf8P//Oc0= X-Received: by 2002:a5d:58d5:0:b0:374:fa15:a8b6 with SMTP id ffacd0b85a97d-378895ca2f8mr10905567f8f.18.1726058033894; Wed, 11 Sep 2024 05:33:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGJVF8zBIN7L71MwlWFNzon39T5/XJjASYYZ/v56EQTQLyNfph/jJ87Yzi9MocTAA9cQWD9w== X-Received: by 2002:a5d:58d5:0:b0:374:fa15:a8b6 with SMTP id ffacd0b85a97d-378895ca2f8mr10905536f8f.18.1726058033374; Wed, 11 Sep 2024 05:33:53 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895649b93sm11471612f8f.3.2024.09.11.05.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:33:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Lei Wang , Xin Li , "Xin Li (Intel)" Subject: [PULL 03/17] target/i386: Raise the highest index value used for any VMCS encoding Date: Wed, 11 Sep 2024 14:33:28 +0200 Message-ID: <20240911123342.339482-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Lei Wang Because the index value of the VMCS field encoding of FRED injected-event data (one of the newly added VMCS fields for FRED transitions), 0x52, is larger than any existing index value, raise the highest index value used for any VMCS encoding to 0x52. Because the index value of the VMCS field encoding of Secondary VM-exit controls, 0x44, is larger than any existing index value, raise the highest index value used for any VMCS encoding to 0x44. Co-developed-by: Xin Li Signed-off-by: Xin Li Signed-off-by: Lei Wang Signed-off-by: Xin Li (Intel) Link: https://lore.kernel.org/r/20240807081813.735158-4-xin@zytor.com Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 1 + target/i386/kvm/kvm.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 2bf37dd15e0..9c39384ac0a 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1186,6 +1186,7 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); #define VMX_VM_EXIT_PT_CONCEAL_PIP 0x01000000 #define VMX_VM_EXIT_CLEAR_IA32_RTIT_CTL 0x02000000 #define VMX_VM_EXIT_LOAD_IA32_PKRS 0x20000000 +#define VMX_VM_EXIT_ACTIVATE_SECONDARY_CONTROLS 0x80000000 #define VMX_VM_ENTRY_LOAD_DEBUG_CONTROLS 0x00000004 #define VMX_VM_ENTRY_IA32E_MODE 0x00000200 diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 2fa88ef1e37..381f414d1e0 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3694,7 +3694,14 @@ static void kvm_msr_entry_add_vmx(X86CPU *cpu, FeatureWordArray f) kvm_msr_entry_add(cpu, MSR_IA32_VMX_CR4_FIXED0, CR4_VMXE_MASK); - if (f[FEAT_VMX_SECONDARY_CTLS] & VMX_SECONDARY_EXEC_TSC_SCALING) { + if (f[FEAT_7_1_EAX] & CPUID_7_1_EAX_FRED) { + /* FRED injected-event data (0x2052). */ + kvm_msr_entry_add(cpu, MSR_IA32_VMX_VMCS_ENUM, 0x52); + } else if (f[FEAT_VMX_EXIT_CTLS] & + VMX_VM_EXIT_ACTIVATE_SECONDARY_CONTROLS) { + /* Secondary VM-exit controls (0x2044). */ + kvm_msr_entry_add(cpu, MSR_IA32_VMX_VMCS_ENUM, 0x44); + } else if (f[FEAT_VMX_SECONDARY_CTLS] & VMX_SECONDARY_EXEC_TSC_SCALING) { /* TSC multiplier (0x2032). */ kvm_msr_entry_add(cpu, MSR_IA32_VMX_VMCS_ENUM, 0x32); } else { From patchwork Wed Sep 11 12:33:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800464 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69AFCEE49A0 for ; Wed, 11 Sep 2024 12:34:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMXu-0005AL-PR; Wed, 11 Sep 2024 08:34:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXs-0004wN-9T for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXq-00012P-Fo for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B8BWBynZiqu5W0tPrxT2WqoU5n0IrKBPLt4KWbMfpz8=; b=QYI4E755MXET1vFeuHLrMUDuMAPyCcNgrB6MaWjhgsy8YOmwaUObLj118yh35gyQwg0kuI 6Uzmgyjmdple/EUp6wVHShd3dI5/Kbuz4XAdb2crSCeorS84fgVK9Cs42G/+dqtrKoVPvS Zesj9CMGeBXjAPwDt89oZyENFLmBF90= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-ZF2Fjw8pPDuupRtz-_Bdeg-1; Wed, 11 Sep 2024 08:33:58 -0400 X-MC-Unique: ZF2Fjw8pPDuupRtz-_Bdeg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-374b35856aeso938407f8f.3 for ; Wed, 11 Sep 2024 05:33:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058036; x=1726662836; 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=B8BWBynZiqu5W0tPrxT2WqoU5n0IrKBPLt4KWbMfpz8=; b=M8wQyJCcxqkSpd9DDfasM5EH+mido4HpkACTOIMEPcr3ET66eBTVunOsValbT3zGEL gFiR89nP3PnWax8fyWzfNS4C0D7d2scHaGlMi5baI8y0vblve3tBo2Mx6g8V3rpW/Yi8 Fv+8Pe8iigycsafC0o6+ZGOuHWptROhcCVyIaCbxvRDtqVjC4hC9KuImeoWyAX7lGNkw xAXqCU20DEFlGBeK2lFDvobOMYBlkJ/zQRqEuk0sV9usX6+9Yj+TCE94+cbpY05C197u CzMSvTlACkHIKON5qfHdTPatCcOutQ5XAu2AIGyKISv0F4aqJVm8cuLFPZX9HvljDptZ NXpw== X-Gm-Message-State: AOJu0YxnGUZF+IVAGGWJNhNVMCL0yjOt+OWqxWPovsPwX9wlZiPooSb2 7z4pCkj7wkZVLVxC5QjNQscYiiTJZ7HWyJ+aNUw7qrtD8QRG7D5Wgp9iw2AA8rWDZKk7fWrPElx DzwGJuGI9l9tEGxkExubcUn6XGfHL6jR0+ddOZc8GAX5LfbQmGxHSrqvutvkYAPK18AVPt6V/QL 1jvv0Yby0tFbAq4VzXR/r8Dv/Ntv/qoeiexwRS67I= X-Received: by 2002:a5d:684a:0:b0:374:c022:fa76 with SMTP id ffacd0b85a97d-378b07feb93mr1812921f8f.37.1726058036480; Wed, 11 Sep 2024 05:33:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVwR8ZfTNReuKjdEEN7FcHAuSFYvvecyZ/v+rFPJnXROdocavS5PKCZKDZo2TD+j0LfZ2wsA== X-Received: by 2002:a5d:684a:0:b0:374:c022:fa76 with SMTP id ffacd0b85a97d-378b07feb93mr1812900f8f.37.1726058035999; Wed, 11 Sep 2024 05:33:55 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956dd932sm11446224f8f.98.2024.09.11.05.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:33:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: "Richard W.M. Jones" Subject: [PULL 04/17] tests/unit: remove block layer code from test-nested-aio-poll Date: Wed, 11 Sep 2024 14:33:29 +0200 Message-ID: <20240911123342.339482-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org GCC is reporting a NULL pointer dereference when compiling aio_wait_kick() with LTO. The issue is that test-nested-aio-poll.c does not call qemu_init_main_loop(). It doesn't _need_ to because it never calls AIO_WAIT_WHILE(), but it seems that LTO does not do enough dead-code elimination to catch that. Fortunately aio_wait_kick() is only used in few places, and only in block layer or system emulation code; and this test only needs the core event loop functionality. It does not even need iothreads. So remove everything that calls aio_wait_kick(), which is nice for coverage compared to adding the call to qemu_init_main_loop(). Reported-by: Richard W.M. Jones Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2434 Signed-off-by: Paolo Bonzini --- tests/unit/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 490ab8182dc..6c377917636 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -115,7 +115,7 @@ if have_block if host_os != 'windows' tests += { 'test-image-locking': [testblock], - 'test-nested-aio-poll': [testblock], + 'test-nested-aio-poll': [], } endif if config_host_data.get('CONFIG_REPLICATION') From patchwork Wed Sep 11 12:33:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC2FFEE499D for ; Wed, 11 Sep 2024 12:34:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMXy-0005X5-Vo; Wed, 11 Sep 2024 08:34:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXt-00050r-4c for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXr-00012U-1F for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P1muO7aVC7mT7zEk/C07F6EvF/ytJrxOdC9V2ewUNBQ=; b=Mob7F95if5U8dVn+OnY9qNy219VvEjuEovNta1FOHjvbKQh4xx5dN6aLIUMjKAOIwnlNP+ HlTrOpWCmhuOi07qzXotN0H3RzbQ3eELSnDvhqsNVdgInkQugpLm/9ywbZmIxuckya7dEK yNy09Iid6AVtFiCCbfdGKDvLfaxhU3A= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-WQEL6bpCOK-zH8KGR2sPPw-1; Wed, 11 Sep 2024 08:34:01 -0400 X-MC-Unique: WQEL6bpCOK-zH8KGR2sPPw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-374c44e58a9so3450094f8f.1 for ; Wed, 11 Sep 2024 05:34:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058039; x=1726662839; 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=P1muO7aVC7mT7zEk/C07F6EvF/ytJrxOdC9V2ewUNBQ=; b=e9hiw+acnJaZN/quWpcZO8ttXTPp3kxe/Z7PDD1YxZxxkeuC8VEjd/1qmfGyInFzeD JhcPCPnAUoP2okLcqyRiwTjyxhsW7+jsldQcHUo7YI3g1oLn02bRMg+sAlax0WfzMRfP BQyABwUB+x14NkoyD83P+lYHB8CFJF+GiAAtetohKWUsuh3M/bLy7qlvejbxKjg0Vyvp Xt1ZbnWxqCQKKMu1BnmghjyekNhU57ud//AK74qhoIAC1T/cryACoT3CjCa8KQuwzFRZ +xKyQVHzSoumY6o92d6dZjo2jM4ZoyJPm0P2tN/30KzaTSlbJps1wqqb6BU6RNSuw3PY ClAQ== X-Gm-Message-State: AOJu0YzpgTAQeeQENgCE8NJTKansaea1eQgg+FKYwwmiFNrLXsLSlQNI Cwp5wxr0WAJzQuU0G3168t/UR9FniCNkOPxSBygyURu0ztcgQAUm0F06f//Spvge1PjeKj2pdNT J/fAUDD5FgtomvHz14Owo4JsSpsTS3u9pB25KKDbiDUwnJbMlMQxYJyZVROmJq8Yt7FSJ/N8pmK gCxbDoDCJY1n9U0EXviZQbgOuLyAXdkBGXqpfDkxg= X-Received: by 2002:a5d:558d:0:b0:374:bcc7:b9bb with SMTP id ffacd0b85a97d-378896100e6mr11198554f8f.35.1726058039461; Wed, 11 Sep 2024 05:33:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHU2UDkvAs+nt+uHc8F2lvTHNdGdImuFRcxGDWZQyAykrxIx5tQs/C6WWWJT4MeYg8cZ+NoYg== X-Received: by 2002:a5d:558d:0:b0:374:bcc7:b9bb with SMTP id ffacd0b85a97d-378896100e6mr11198537f8f.35.1726058038970; Wed, 11 Sep 2024 05:33:58 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3789567609esm11470721f8f.59.2024.09.11.05.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:33:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?utf-8?q?Kamil_Szcz=C4=99k?= Subject: [PULL 05/17] hw/i386/pc: Add a description for the i8042 property Date: Wed, 11 Sep 2024 14:33:30 +0200 Message-ID: <20240911123342.339482-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Kamil Szczęk While working on exposing the i8042 property in libvirt I noticed that the property is missing a description. This adds a simple description so that QEMU users don't have to dig in the source code to figure out what this option does. Signed-off-by: Kamil Szczęk Link: https://lore.kernel.org/r/15fhXFY6x78KW8P5gw0eKTW8kc17zejrJFxqnOyoBy6vw4W9rCmgDhoxssWosWFs_dbFtfsyjn9wpPrV3x8Nlzhy8mTJSEnXCr4qyHAhXSw=@szczek.dev Signed-off-by: Paolo Bonzini --- hw/i386/pc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 7779c88a91e..f4df8637ef0 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1817,6 +1817,8 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) object_class_property_add_bool(oc, PC_MACHINE_I8042, pc_machine_get_i8042, pc_machine_set_i8042); + object_class_property_set_description(oc, PC_MACHINE_I8042, + "Enable/disable Intel 8042 PS/2 controller emulation"); object_class_property_add_bool(oc, "default-bus-bypass-iommu", pc_machine_get_default_bus_bypass_iommu, From patchwork Wed Sep 11 12:33:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2473EE499F for ; Wed, 11 Sep 2024 12:38:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMXx-0005VD-NA; Wed, 11 Sep 2024 08:34:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXv-0005H5-Kl for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXt-00012u-LA for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pit7qiYVqnOWSVjEH0t9en0kWfam4PoVe6YUyM257fE=; b=Fqx0A5tyDLp2yzzOTqTHfnI+4qw+YFi6MMewuwM1GAIcdPlMF3vPrQE01NAFpEWJ/yYh+Q 0E6/bGxbrmNXg4XIv8ha3IwlaRhKuO80YYTnw3s7YV10pEbvkSBgLnsztgF8FP061xd3GP WHtWjtolLWRhoMNebhxuCTGCoZCoQp8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-p4mEJYwUOLKIPs-Kb8fT6w-1; Wed, 11 Sep 2024 08:34:04 -0400 X-MC-Unique: p4mEJYwUOLKIPs-Kb8fT6w-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42cb0ed9072so37259025e9.1 for ; Wed, 11 Sep 2024 05:34:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058042; x=1726662842; 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=Pit7qiYVqnOWSVjEH0t9en0kWfam4PoVe6YUyM257fE=; b=Hf62JALdAIcHVTuCjsV5ceIluvntqbqajYFyl6MPFZaqVjmZcMsEYs1UT71m5svLQy dxC02zFI/e/estb2wfBA6V4kOG5LLfTSn6URymL9pWDb2eEGeiKMNCHlG7LlArqEIJj1 UGcH7yEWA77SvftugLq0xMgjozRVcFPcex0U4MU6Ap905I6+KSM9lybsHScGSRHGtSva KdAlunDSdLAwBUaE01X3ClWf3Nsn8CDPmEg3vaR9lwDtGoFUfo38bl/zsImCZ/GRgyb5 69H/l3UC+0Xkxw2lin1SP9coPvoiJVl2EGQWYaeoLEFhiEpXST2PBt+ISfLcyrV4hRFu KASg== X-Gm-Message-State: AOJu0YyT+QHdKfe0r6n3dVBgmpqi6Cs1iyFh/HzqVZWrsKyW6Yjfq+3k 6vW9tnnv6Sqqy28/1et1SF9+K6+qS8V8ZSbsEg3XqmvCDQQbBrTZ7AN7HXzecZz+oGp4w5nRrLT c9ivdKJqV4d3VBiXwT4Xy/XAxl7VKoqvh60Q3DOr0OKf9GJ+jgMS9q/jKlW9JWz3EEvt4X8GxeU UnWUVccSklOP9fguQFSJnXJTp3Ntuj4mK7uq2uu1o= X-Received: by 2002:a05:600c:358a:b0:42c:b950:6821 with SMTP id 5b1f17b1804b1-42cb9506a4amr83041095e9.19.1726058042011; Wed, 11 Sep 2024 05:34:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPWOPoXwIRnhEFSJs4L0bBpigenF/2c5N4PsmiDOGtEEWyhQYmJ1jtGqUQP5AttL87YqQpXw== X-Received: by 2002:a05:600c:358a:b0:42c:b950:6821 with SMTP id 5b1f17b1804b1-42cb9506a4amr83040825e9.19.1726058041501; Wed, 11 Sep 2024 05:34:01 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42caeb449aesm140800895e9.25.2024.09.11.05.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ani Sinha , philmd@linaro.org Subject: [PULL 06/17] kvm/i386: make kvm_filter_msr() and related definitions private to kvm module Date: Wed, 11 Sep 2024 14:33:31 +0200 Message-ID: <20240911123342.339482-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Ani Sinha kvm_filer_msr() is only used from i386 kvm module. Make it static so that its easy for developers to understand that its not used anywhere else. Same for QEMURDMSRHandler, QEMUWRMSRHandler and KVMMSRHandlers definitions. CC: philmd@linaro.org Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Ani Sinha Link: https://lore.kernel.org/r/20240903140045.41167-1-anisinha@redhat.com [Make struct unnamed. - Paolo] Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm_i386.h | 11 ----------- target/i386/kvm/kvm.c | 12 +++++++++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index 34fc60774b8..9de9c0d3038 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -66,17 +66,6 @@ uint64_t kvm_swizzle_msi_ext_dest_id(uint64_t address); void kvm_update_msi_routes_all(void *private, bool global, uint32_t index, uint32_t mask); -typedef bool QEMURDMSRHandler(X86CPU *cpu, uint32_t msr, uint64_t *val); -typedef bool QEMUWRMSRHandler(X86CPU *cpu, uint32_t msr, uint64_t val); -typedef struct kvm_msr_handlers { - uint32_t msr; - QEMURDMSRHandler *rdmsr; - QEMUWRMSRHandler *wrmsr; -} KVMMSRHandlers; - -bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, - QEMUWRMSRHandler *wrmsr); - #endif /* CONFIG_KVM */ void kvm_pc_setup_irq_routing(bool pci_enabled); diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 381f414d1e0..d95013a2ce6 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -92,7 +92,17 @@ * 255 kvm_msr_entry structs */ #define MSR_BUF_SIZE 4096 +typedef bool QEMURDMSRHandler(X86CPU *cpu, uint32_t msr, uint64_t *val); +typedef bool QEMUWRMSRHandler(X86CPU *cpu, uint32_t msr, uint64_t val); +typedef struct { + uint32_t msr; + QEMURDMSRHandler *rdmsr; + QEMUWRMSRHandler *wrmsr; +} KVMMSRHandlers; + static void kvm_init_msrs(X86CPU *cpu); +static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, + QEMUWRMSRHandler *wrmsr); const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_INFO(SET_TSS_ADDR), @@ -5735,7 +5745,7 @@ static bool kvm_install_msr_filters(KVMState *s) return true; } -bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, +static bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, QEMUWRMSRHandler *wrmsr) { int i; From patchwork Wed Sep 11 12:33:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A9E8EE49A0 for ; Wed, 11 Sep 2024 12:37:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMY1-000650-2F; Wed, 11 Sep 2024 08:34:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXy-0005mh-KU for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXw-00013V-Fe for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xtYCdte9dWd9oGT6jGVa2VRP3oHQUflr0u1OJvVB2MA=; b=gFtsPBnO0IJ+0Xzyo0Op987NZbZfQuzdC3AYd8fHfgbLaMIbe4MSrZoT0DzcBLu6e31YR4 eI16369PiTewo5XQW2pFYgmiTW8XGRaRHUgVw748HU3Zmrk02LoW40Ec8EEkmjpW6GC+uc 0hKmpCjBCbm6Ocfekg9CxfKa8uHR2zM= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-Wz8Rcq_KPZ-vB-UsiYMfHQ-1; Wed, 11 Sep 2024 08:34:06 -0400 X-MC-Unique: Wz8Rcq_KPZ-vB-UsiYMfHQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-374b9617ab0so2863216f8f.3 for ; Wed, 11 Sep 2024 05:34:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058045; x=1726662845; 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=xtYCdte9dWd9oGT6jGVa2VRP3oHQUflr0u1OJvVB2MA=; b=EMWfj5453TfceR7FqnzMGLvHtDveZJ+O2g6XYRq6jAytjCGxOsOUBgyaWMRfGrIHip QvqD2Mcqt5MffhMUKg8aCLT195OHS/10F/pLvZPxlmwT5++pKStq2XECHAzgqDv26Dcz lrK8tD4+5kS1/6yuW8kBKiWHP20MIY/omdxCI6sufzPs2KmIBHbpGkbc6AsWWmwSXkZF YVB08pz8I7TGUewLLDrE52hRcB5343q+jzlTLC4a+1O3FkuQBjWnaKhhVYtPR+AaS8xQ m+cZw5ha5gCijJC2o1HSKdlNhdLy2SMmBa+n1mPuDf2eaNS1xF/9RV6F+mpHx9VGIgot 0Ong== X-Gm-Message-State: AOJu0Yxevt1BqPXTBjzJbL/WRQZtb9DLzmIQfzUBV7no4QLJ8aSFIJBq WE373ObNVlMhn4k0zETJ9E4Yoe9EPJHHJo7rbgRDuNH2wK138CJewamGSge0T71pk7TQccrBx3p c7Up3i7lf2rBVcPLPb89/OoYiLmUAMkqYLXDEQsP3EoukJIRxd6wCQQtKRI7TgGuKgmalOutm7d uDfc2q71rIC75Jo1LIlnGtJg2KmK53aHaEQDMYTLU= X-Received: by 2002:a5d:4991:0:b0:368:5bb4:169b with SMTP id ffacd0b85a97d-378926858b2mr7941981f8f.4.1726058044579; Wed, 11 Sep 2024 05:34:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNafR3vo7C/29BOJu4tasZKxMizFSJ9u+6mePFyBtocHZYI8Q8jgAoAWHtyi+3mSLgGSQK9w== X-Received: by 2002:a5d:4991:0:b0:368:5bb4:169b with SMTP id ffacd0b85a97d-378926858b2mr7941958f8f.4.1726058044030; Wed, 11 Sep 2024 05:34:04 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d35b9sm11476718f8f.70.2024.09.11.05.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ani Sinha Subject: [PULL 07/17] kvm/i386: fix return values of is_host_cpu_intel() Date: Wed, 11 Sep 2024 14:33:32 +0200 Message-ID: <20240911123342.339482-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Ani Sinha is_host_cpu_intel() should return TRUE if the host cpu in Intel based, otherwise it should return FALSE. Currently, it returns zero (FALSE) when the host CPU is INTEL and non-zero otherwise. Fix the function so that it agrees more with the semantics. Adjust the calling logic accordingly. RAPL needs Intel host cpus. If the host CPU is not Intel baseed, we should report error. Signed-off-by: Ani Sinha Link: https://lore.kernel.org/r/20240903080004.33746-1-anisinha@redhat.com [While touching the code remove too many spaces from the second part of the error. - Paolo] Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm.c | 6 +++--- target/i386/kvm/vmsr_energy.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index d95013a2ce6..7c491378026 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2906,9 +2906,9 @@ static int kvm_msr_energy_thread_init(KVMState *s, MachineState *ms) * 1. Host cpu must be Intel cpu * 2. RAPL must be enabled on the Host */ - if (is_host_cpu_intel()) { - error_report("The RAPL feature can only be enabled on hosts\ - with Intel CPU models"); + if (!is_host_cpu_intel()) { + error_report("The RAPL feature can only be enabled on hosts " + "with Intel CPU models"); ret = 1; goto out; } diff --git a/target/i386/kvm/vmsr_energy.c b/target/i386/kvm/vmsr_energy.c index 7e064c5aef3..31508d4e77a 100644 --- a/target/i386/kvm/vmsr_energy.c +++ b/target/i386/kvm/vmsr_energy.c @@ -34,7 +34,7 @@ bool is_host_cpu_intel(void) host_cpu_vendor_fms(vendor, &family, &model, &stepping); - return strcmp(vendor, CPUID_VENDOR_INTEL); + return g_str_equal(vendor, CPUID_VENDOR_INTEL); } int is_rapl_enabled(void) From patchwork Wed Sep 11 12:33:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9AEAEE499F for ; Wed, 11 Sep 2024 12:34:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMY9-0007Dz-4R; Wed, 11 Sep 2024 08:34:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMY2-0006OW-Nh for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMXz-00014G-Rh for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mBgLkkL3Ij9Xb+6zZYO4yZDOwxGEAxoAbZBtbC+FfYw=; b=Ta88RH6EL8tz3FOr+y0xeR/d9XevWxI2XRLniQGIHom+gyFHU4RxVkjtFHVHus6FkICpEH yBZnHsOBO371Rd84b/Ml38BYcrMCJ1eiY9xvPn6SmaKbWmMtMcLoMqGMgAAVtuZyLfypCq /4CdAfhcoDkhIyrfwGoCv0ysppEUvjs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-AWbIQKy8M-i0UJMBrZOjIw-1; Wed, 11 Sep 2024 08:34:09 -0400 X-MC-Unique: AWbIQKy8M-i0UJMBrZOjIw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42cb89fbb8cso21731775e9.0 for ; Wed, 11 Sep 2024 05:34:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058048; x=1726662848; 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=mBgLkkL3Ij9Xb+6zZYO4yZDOwxGEAxoAbZBtbC+FfYw=; b=LuFpQ4+YMofj/4o8V9A+AGMC7D/V5Djoh2kz2wz2b1Uj7aUpg+b7r1ffkGUtHCAAWJ VTMMFisgSlIvtdEDZZxtN8WWBSRiB3q/EnZxE2TjKrHkzsRV00hgCXK/zkgxmvtU5nlv +dXR54Klj8mACbg7SSSYKjCQ/tlKYonwys2N5qbGlRKJa23vKE7mn52KZvtWY8fLAP4B 0OqWOXZEB+ysKmt53/Ym4BBTjgDaSMHBvH3FwJttTUKKUluH4ZHiHeoXufShp0xUmN9I 6ySma3xSt6MtrqKXYiWEdjxfFgBz2K7j6gvYAYEhFD8moAyZDfkssEyu6rzFO1vqkB4a ozQg== X-Gm-Message-State: AOJu0Ywt/OzKU2K7G/GDPF9v1PoBaosuNC4SjTmPAogdYTi7j5/bJ8kH Ey6iztK23eOm+3ECpFQkVWKNWJ72gdcTstQvnVRIWHjLj0eLrbJtKdWI9uwpsMuX/7fsXYIyJLv DTwq2Bfa3T8MBIZYSDoSDfzZJC8RHC1njVImLp0I+jCJNb/qlDkLP8GnH3kRsACpfpH0efPhiqY aunDbKNnOHXS1vdfYZ6dvacdr7aWUTPEBNvOpkN5c= X-Received: by 2002:a05:600c:45c8:b0:429:dc88:7e65 with SMTP id 5b1f17b1804b1-42cad760eedmr101160115e9.12.1726058047886; Wed, 11 Sep 2024 05:34:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHndJ996xi0cDrIvpw8cBgdEm0rBe9b+En4atTREDihcyNBz2Hu1sd8h5zKcisloIazlU0Kug== X-Received: by 2002:a05:600c:45c8:b0:429:dc88:7e65 with SMTP id 5b1f17b1804b1-42cad760eedmr101159735e9.12.1726058047239; Wed, 11 Sep 2024 05:34:07 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3796sm11446737f8f.80.2024.09.11.05.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ani Sinha , qemu-trivial@nongnu.org, zhao1.liu@intel.com, armbru@redhat.com Subject: [PULL 08/17] kvm: replace fprintf with error_report()/printf() in kvm_init() Date: Wed, 11 Sep 2024 14:33:33 +0200 Message-ID: <20240911123342.339482-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Ani Sinha error_report() is more appropriate for error situations. Replace fprintf with error_report() and error_printf() as appropriate. Some improvement in error reporting also happens as a part of this change. For example: From: $ ./qemu-system-x86_64 --accel kvm Could not access KVM kernel module: No such file or directory To: $ ./qemu-system-x86_64 --accel kvm qemu-system-x86_64: --accel kvm: Could not access KVM kernel module: No such file or directory CC: qemu-trivial@nongnu.org CC: zhao1.liu@intel.com CC: armbru@redhat.com Reviewed-by: Zhao Liu Reviewed-by: Markus Armbruster Signed-off-by: Ani Sinha Link: https://lore.kernel.org/r/20240828124539.62672-1-anisinha@redhat.com Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 75d11a07b2b..fcc157f0e60 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2427,7 +2427,7 @@ static int kvm_init(MachineState *ms) QLIST_INIT(&s->kvm_parked_vcpus); s->fd = qemu_open_old(s->device ?: "/dev/kvm", O_RDWR); if (s->fd == -1) { - fprintf(stderr, "Could not access KVM kernel module: %m\n"); + error_report("Could not access KVM kernel module: %m"); ret = -errno; goto err; } @@ -2437,13 +2437,13 @@ static int kvm_init(MachineState *ms) if (ret >= 0) { ret = -EINVAL; } - fprintf(stderr, "kvm version too old\n"); + error_report("kvm version too old"); goto err; } if (ret > KVM_API_VERSION) { ret = -EINVAL; - fprintf(stderr, "kvm version not supported\n"); + error_report("kvm version not supported"); goto err; } @@ -2488,26 +2488,22 @@ static int kvm_init(MachineState *ms) } while (ret == -EINTR); if (ret < 0) { - fprintf(stderr, "ioctl(KVM_CREATE_VM) failed: %d %s\n", -ret, - strerror(-ret)); + error_report("ioctl(KVM_CREATE_VM) failed: %s", strerror(-ret)); #ifdef TARGET_S390X if (ret == -EINVAL) { - fprintf(stderr, - "Host kernel setup problem detected. Please verify:\n"); - fprintf(stderr, "- for kernels supporting the switch_amode or" - " user_mode parameters, whether\n"); - fprintf(stderr, - " user space is running in primary address space\n"); - fprintf(stderr, - "- for kernels supporting the vm.allocate_pgste sysctl, " - "whether it is enabled\n"); + error_printf("Host kernel setup problem detected." + " Please verify:\n"); + error_printf("- for kernels supporting the" + " switch_amode or user_mode parameters, whether"); + error_printf(" user space is running in primary address space\n"); + error_printf("- for kernels supporting the vm.allocate_pgste" + " sysctl, whether it is enabled\n"); } #elif defined(TARGET_PPC) if (ret == -EINVAL) { - fprintf(stderr, - "PPC KVM module is not loaded. Try modprobe kvm_%s.\n", - (type == 2) ? "pr" : "hv"); + error_printf("PPC KVM module is not loaded. Try modprobe kvm_%s.\n", + (type == 2) ? "pr" : "hv"); } #endif goto err; @@ -2526,9 +2522,9 @@ static int kvm_init(MachineState *ms) nc->name, nc->num, soft_vcpus_limit); if (nc->num > hard_vcpus_limit) { - fprintf(stderr, "Number of %s cpus requested (%d) exceeds " - "the maximum cpus supported by KVM (%d)\n", - nc->name, nc->num, hard_vcpus_limit); + error_report("Number of %s cpus requested (%d) exceeds " + "the maximum cpus supported by KVM (%d)", + nc->name, nc->num, hard_vcpus_limit); exit(1); } } @@ -2542,8 +2538,8 @@ static int kvm_init(MachineState *ms) } if (missing_cap) { ret = -EINVAL; - fprintf(stderr, "kvm does not support %s\n%s", - missing_cap->name, upgrade_note); + error_report("kvm does not support %s", missing_cap->name); + error_printf("%s", upgrade_note); goto err; } From patchwork Wed Sep 11 12:33:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800498 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54CDDEE499D for ; Wed, 11 Sep 2024 12:44:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMYZ-0000f5-C6; Wed, 11 Sep 2024 08:34:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMY7-000771-6c for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMY3-00015P-DK for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zGeZgIGKohb2btdPq5ZukYQwzEejnWvtto4cnM/cPhk=; b=baZkaaoB72HG02dmQhJgKLKtrDKYWEi+H88Hd1OZDxLgtUOD6yLjA7H+e3kVNGrbHP4FUG ehC/g91QJbGcQ5vXQRMDrjAaqrSVxgLmCC24qm5zrEnC96FK4VjCjyqXcw5CjGxFcOT+XW AMXdaiB4KSsnrnmCZi1dwFtfipv9318= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-568-_DtppuHhOOKE2PVoQ8bmGQ-1; Wed, 11 Sep 2024 08:34:13 -0400 X-MC-Unique: _DtppuHhOOKE2PVoQ8bmGQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3730b54347cso743182f8f.1 for ; Wed, 11 Sep 2024 05:34:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058052; x=1726662852; 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=zGeZgIGKohb2btdPq5ZukYQwzEejnWvtto4cnM/cPhk=; b=gi5aJpaF6PywR8FYm/WMVZ1V1cR3vp+BP7Ah3Hg/zyH82Jr+EyWK/0ofEWXb/02g5s KiiVaAsO8RaaOUsVxpLEkk7fxZlfHnQEW4Nk4bLy3MPwzJ3SSzTnLumpE5kzJKse1SV9 HrOWHuTEFUTpaYxCCTNtvgcxl8FB2busZ2tSuJUtQKk+kaYH2o+rb9PrGrPPFnI858ks y96PxjpPA4HQtGPJ1jTooJBphT2ZegilyL805hqsfZqHdEFSVJQXUasyWZyYVNtByixa +PgOr3Hk6tRIr+4F8CQSWdQbtbrmV6XT+DJE+xPHpd7klLQBFitRs9rXJBCtvFjsEGoT czfg== X-Gm-Message-State: AOJu0YwhxQBie/BOgCjjgKeTaCMO7BnByf7Kk4CpBupG4DfRalH8SH/P /30xuc28x8fp9N900eeJJFKT0AqTIVTViMnDcINg5T2VBTLKo6sU0nKyn2nTzCabgwVWK6b5GrL jiuZaDi4YmOpP2+AGhaWUykfs0umiSsPblvTvhPt5J4prarQ/4awez40/S5lOabtScfpDOpGj65 Z6UtmbCt9RtmjA2gLI65MkITpy5I5F571zDgDUjyo= X-Received: by 2002:a5d:4528:0:b0:378:7de9:3716 with SMTP id ffacd0b85a97d-378b0796de0mr1566269f8f.8.1726058051905; Wed, 11 Sep 2024 05:34:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5El2h0ECUDnYNIOrPZx+M4cFwrid5q6KZ2OdgmX6YxVWkLoCgOpuUuG4i0GJXPcYgn2dcZg== X-Received: by 2002:a5d:4528:0:b0:378:7de9:3716 with SMTP id ffacd0b85a97d-378b0796de0mr1566255f8f.8.1726058051349; Wed, 11 Sep 2024 05:34:11 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cb1e3a5fdsm127851555e9.48.2024.09.11.05.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ani Sinha Subject: [PULL 09/17] kvm/i386: refactor kvm_arch_init and split it into smaller functions Date: Wed, 11 Sep 2024 14:33:34 +0200 Message-ID: <20240911123342.339482-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Ani Sinha kvm_arch_init() enables a lot of vm capabilities. Refactor them into separate smaller functions. Energy MSR related operations also moved to its own function. There should be no functional impact. Signed-off-by: Ani Sinha Link: https://lore.kernel.org/r/20240903124143.39345-2-anisinha@redhat.com Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm.c | 337 ++++++++++++++++++++++++++---------------- 1 file changed, 211 insertions(+), 126 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 7c491378026..599faf0ac6e 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -3005,10 +3005,197 @@ int kvm_arch_get_default_type(MachineState *ms) return 0; } +static int kvm_vm_enable_exception_payload(KVMState *s) +{ + int ret = 0; + has_exception_payload = kvm_check_extension(s, KVM_CAP_EXCEPTION_PAYLOAD); + if (has_exception_payload) { + ret = kvm_vm_enable_cap(s, KVM_CAP_EXCEPTION_PAYLOAD, 0, true); + if (ret < 0) { + error_report("kvm: Failed to enable exception payload cap: %s", + strerror(-ret)); + } + } + + return ret; +} + +static int kvm_vm_enable_triple_fault_event(KVMState *s) +{ + int ret = 0; + has_triple_fault_event = \ + kvm_check_extension(s, + KVM_CAP_X86_TRIPLE_FAULT_EVENT); + if (has_triple_fault_event) { + ret = kvm_vm_enable_cap(s, KVM_CAP_X86_TRIPLE_FAULT_EVENT, 0, true); + if (ret < 0) { + error_report("kvm: Failed to enable triple fault event cap: %s", + strerror(-ret)); + } + } + return ret; +} + +static int kvm_vm_set_identity_map_addr(KVMState *s, uint64_t *identity_base) +{ + /* + * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code directly. + * In order to use vm86 mode, an EPT identity map and a TSS are needed. + * Since these must be part of guest physical memory, we need to allocate + * them, both by setting their start addresses in the kernel and by + * creating a corresponding e820 entry. We need 4 pages before the BIOS, + * so this value allows up to 16M BIOSes. + */ + *identity_base = 0xfeffc000; + return kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, identity_base); +} + +static int kvm_vm_set_nr_mmu_pages(KVMState *s) +{ + uint64_t shadow_mem; + int ret = 0; + shadow_mem = object_property_get_int(OBJECT(s), + "kvm-shadow-mem", + &error_abort); + if (shadow_mem != -1) { + shadow_mem /= 4096; + ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem); + } + return ret; +} + +static int kvm_vm_set_tss_addr(KVMState *s, uint64_t identity_base) +{ + /* Set TSS base one page after EPT identity map. */ + return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, identity_base); +} + +static int kvm_vm_enable_disable_exits(KVMState *s) +{ + int disable_exits = kvm_check_extension(s, KVM_CAP_X86_DISABLE_EXITS); +/* Work around for kernel header with a typo. TODO: fix header and drop. */ +#if defined(KVM_X86_DISABLE_EXITS_HTL) && !defined(KVM_X86_DISABLE_EXITS_HLT) +#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL +#endif + if (disable_exits) { + disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT | + KVM_X86_DISABLE_EXITS_HLT | + KVM_X86_DISABLE_EXITS_PAUSE | + KVM_X86_DISABLE_EXITS_CSTATE); + } + + return kvm_vm_enable_cap(s, KVM_CAP_X86_DISABLE_EXITS, 0, + disable_exits); +} + +static int kvm_vm_enable_bus_lock_exit(KVMState *s) +{ + int ret = 0; + ret = kvm_check_extension(s, KVM_CAP_X86_BUS_LOCK_EXIT); + if (!(ret & KVM_BUS_LOCK_DETECTION_EXIT)) { + error_report("kvm: bus lock detection unsupported"); + return -ENOTSUP; + } + ret = kvm_vm_enable_cap(s, KVM_CAP_X86_BUS_LOCK_EXIT, 0, + KVM_BUS_LOCK_DETECTION_EXIT); + if (ret < 0) { + error_report("kvm: Failed to enable bus lock detection cap: %s", + strerror(-ret)); + } + + return ret; +} + +static int kvm_vm_enable_notify_vmexit(KVMState *s) +{ + int ret = 0; + if (!kvm_check_extension(s, KVM_CAP_X86_NOTIFY_VMEXIT)) { + error_report("kvm: notify vmexit unsupported"); + return -ENOTSUP; + } + + if (s->notify_vmexit != NOTIFY_VMEXIT_OPTION_DISABLE) { + uint64_t notify_window_flags = + ((uint64_t)s->notify_window << 32) | + KVM_X86_NOTIFY_VMEXIT_ENABLED | + KVM_X86_NOTIFY_VMEXIT_USER; + ret = kvm_vm_enable_cap(s, KVM_CAP_X86_NOTIFY_VMEXIT, 0, + notify_window_flags); + if (ret < 0) { + error_report("kvm: Failed to enable notify vmexit cap: %s", + strerror(-ret)); + } + } + return ret; +} + +static int kvm_vm_enable_userspace_msr(KVMState *s) +{ + int ret; + + if (!kvm_vm_check_extension(s, KVM_CAP_X86_USER_SPACE_MSR)) { + error_report("kvm: userspace MSR not supported"); + return -ENOTSUP; + } + + ret = kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0, + KVM_MSR_EXIT_REASON_FILTER); + if (ret < 0) { + error_report("Could not enable user space MSRs: %s", + strerror(-ret)); + exit(1); + } + + if (!kvm_filter_msr(s, MSR_CORE_THREAD_COUNT, + kvm_rdmsr_core_thread_count, NULL)) { + error_report("Could not install MSR_CORE_THREAD_COUNT handler!"); + exit(1); + } + + return 0; +} + +static void kvm_vm_enable_energy_msrs(KVMState *s) +{ + bool r; + if (s->msr_energy.enable == true) { + r = kvm_filter_msr(s, MSR_RAPL_POWER_UNIT, + kvm_rdmsr_rapl_power_unit, NULL); + if (!r) { + error_report("Could not install MSR_RAPL_POWER_UNIT \ + handler"); + exit(1); + } + + r = kvm_filter_msr(s, MSR_PKG_POWER_LIMIT, + kvm_rdmsr_pkg_power_limit, NULL); + if (!r) { + error_report("Could not install MSR_PKG_POWER_LIMIT \ + handler"); + exit(1); + } + + r = kvm_filter_msr(s, MSR_PKG_POWER_INFO, + kvm_rdmsr_pkg_power_info, NULL); + if (!r) { + error_report("Could not install MSR_PKG_POWER_INFO \ + handler"); + exit(1); + } + r = kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS, + kvm_rdmsr_pkg_energy_status, NULL); + if (!r) { + error_report("Could not install MSR_PKG_ENERGY_STATUS \ + handler"); + exit(1); + } + } + return; +} + int kvm_arch_init(MachineState *ms, KVMState *s) { uint64_t identity_base = 0xfffbc000; - uint64_t shadow_mem; int ret; struct utsname utsname; Error *local_err = NULL; @@ -3038,24 +3225,14 @@ int kvm_arch_init(MachineState *ms, KVMState *s) hv_vpindex_settable = kvm_check_extension(s, KVM_CAP_HYPERV_VP_INDEX); - has_exception_payload = kvm_check_extension(s, KVM_CAP_EXCEPTION_PAYLOAD); - if (has_exception_payload) { - ret = kvm_vm_enable_cap(s, KVM_CAP_EXCEPTION_PAYLOAD, 0, true); - if (ret < 0) { - error_report("kvm: Failed to enable exception payload cap: %s", - strerror(-ret)); - return ret; - } + ret = kvm_vm_enable_exception_payload(s); + if (ret < 0) { + return ret; } - has_triple_fault_event = kvm_check_extension(s, KVM_CAP_X86_TRIPLE_FAULT_EVENT); - if (has_triple_fault_event) { - ret = kvm_vm_enable_cap(s, KVM_CAP_X86_TRIPLE_FAULT_EVENT, 0, true); - if (ret < 0) { - error_report("kvm: Failed to enable triple fault event cap: %s", - strerror(-ret)); - return ret; - } + ret = kvm_vm_enable_triple_fault_event(s); + if (ret < 0) { + return ret; } if (s->xen_version) { @@ -3086,22 +3263,12 @@ int kvm_arch_init(MachineState *ms, KVMState *s) uname(&utsname); lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0; - /* - * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code directly. - * In order to use vm86 mode, an EPT identity map and a TSS are needed. - * Since these must be part of guest physical memory, we need to allocate - * them, both by setting their start addresses in the kernel and by - * creating a corresponding e820 entry. We need 4 pages before the BIOS, - * so this value allows up to 16M BIOSes. - */ - identity_base = 0xfeffc000; - ret = kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, &identity_base); + ret = kvm_vm_set_identity_map_addr(s, &identity_base); if (ret < 0) { return ret; } - /* Set TSS base one page after EPT identity map. */ - ret = kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, identity_base + 0x1000); + ret = kvm_vm_set_tss_addr(s, identity_base + 0x1000); if (ret < 0) { return ret; } @@ -3109,13 +3276,9 @@ int kvm_arch_init(MachineState *ms, KVMState *s) /* Tell fw_cfg to notify the BIOS to reserve the range. */ e820_add_entry(identity_base, 0x4000, E820_RESERVED); - shadow_mem = object_property_get_int(OBJECT(s), "kvm-shadow-mem", &error_abort); - if (shadow_mem != -1) { - shadow_mem /= 4096; - ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem); - if (ret < 0) { - return ret; - } + ret = kvm_vm_set_nr_mmu_pages(s); + if (ret < 0) { + return ret; } if (kvm_check_extension(s, KVM_CAP_X86_SMM) && @@ -3126,20 +3289,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } if (enable_cpu_pm) { - int disable_exits = kvm_check_extension(s, KVM_CAP_X86_DISABLE_EXITS); -/* Work around for kernel header with a typo. TODO: fix header and drop. */ -#if defined(KVM_X86_DISABLE_EXITS_HTL) && !defined(KVM_X86_DISABLE_EXITS_HLT) -#define KVM_X86_DISABLE_EXITS_HLT KVM_X86_DISABLE_EXITS_HTL -#endif - if (disable_exits) { - disable_exits &= (KVM_X86_DISABLE_EXITS_MWAIT | - KVM_X86_DISABLE_EXITS_HLT | - KVM_X86_DISABLE_EXITS_PAUSE | - KVM_X86_DISABLE_EXITS_CSTATE); - } - - ret = kvm_vm_enable_cap(s, KVM_CAP_X86_DISABLE_EXITS, 0, - disable_exits); + ret = kvm_vm_enable_disable_exits(s); if (ret < 0) { error_report("kvm: guest stopping CPU not supported: %s", strerror(-ret)); @@ -3150,16 +3300,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) X86MachineState *x86ms = X86_MACHINE(ms); if (x86ms->bus_lock_ratelimit > 0) { - ret = kvm_check_extension(s, KVM_CAP_X86_BUS_LOCK_EXIT); - if (!(ret & KVM_BUS_LOCK_DETECTION_EXIT)) { - error_report("kvm: bus lock detection unsupported"); - return -ENOTSUP; - } - ret = kvm_vm_enable_cap(s, KVM_CAP_X86_BUS_LOCK_EXIT, 0, - KVM_BUS_LOCK_DETECTION_EXIT); + ret = kvm_vm_enable_bus_lock_exit(s); if (ret < 0) { - error_report("kvm: Failed to enable bus lock detection cap: %s", - strerror(-ret)); return ret; } ratelimit_init(&bus_lock_ratelimit_ctrl); @@ -3168,80 +3310,23 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } - if (s->notify_vmexit != NOTIFY_VMEXIT_OPTION_DISABLE && - kvm_check_extension(s, KVM_CAP_X86_NOTIFY_VMEXIT)) { - uint64_t notify_window_flags = - ((uint64_t)s->notify_window << 32) | - KVM_X86_NOTIFY_VMEXIT_ENABLED | - KVM_X86_NOTIFY_VMEXIT_USER; - ret = kvm_vm_enable_cap(s, KVM_CAP_X86_NOTIFY_VMEXIT, 0, - notify_window_flags); - if (ret < 0) { - error_report("kvm: Failed to enable notify vmexit cap: %s", - strerror(-ret)); - return ret; - } + ret = kvm_vm_enable_notify_vmexit(s); + if (ret < 0) { + return ret; } + if (kvm_vm_check_extension(s, KVM_CAP_X86_USER_SPACE_MSR)) { - bool r; - - ret = kvm_vm_enable_cap(s, KVM_CAP_X86_USER_SPACE_MSR, 0, - KVM_MSR_EXIT_REASON_FILTER); - if (ret) { - error_report("Could not enable user space MSRs: %s", - strerror(-ret)); - exit(1); - } - - r = kvm_filter_msr(s, MSR_CORE_THREAD_COUNT, - kvm_rdmsr_core_thread_count, NULL); - if (!r) { - error_report("Could not install MSR_CORE_THREAD_COUNT handler: %s", - strerror(-ret)); - exit(1); + ret = kvm_vm_enable_userspace_msr(s); + if (ret < 0) { + return ret; } if (s->msr_energy.enable == true) { - r = kvm_filter_msr(s, MSR_RAPL_POWER_UNIT, - kvm_rdmsr_rapl_power_unit, NULL); - if (!r) { - error_report("Could not install MSR_RAPL_POWER_UNIT \ - handler: %s", - strerror(-ret)); + kvm_vm_enable_energy_msrs(s); + if (kvm_msr_energy_thread_init(s, ms)) { + error_report("kvm : error RAPL feature requirement not met"); exit(1); } - - r = kvm_filter_msr(s, MSR_PKG_POWER_LIMIT, - kvm_rdmsr_pkg_power_limit, NULL); - if (!r) { - error_report("Could not install MSR_PKG_POWER_LIMIT \ - handler: %s", - strerror(-ret)); - exit(1); - } - - r = kvm_filter_msr(s, MSR_PKG_POWER_INFO, - kvm_rdmsr_pkg_power_info, NULL); - if (!r) { - error_report("Could not install MSR_PKG_POWER_INFO \ - handler: %s", - strerror(-ret)); - exit(1); - } - r = kvm_filter_msr(s, MSR_PKG_ENERGY_STATUS, - kvm_rdmsr_pkg_energy_status, NULL); - if (!r) { - error_report("Could not install MSR_PKG_ENERGY_STATUS \ - handler: %s", - strerror(-ret)); - exit(1); - } - r = kvm_msr_energy_thread_init(s, ms); - if (r) { - error_report("kvm : error RAPL feature requirement not meet"); - exit(1); - } - } } From patchwork Wed Sep 11 12:33:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF934EE499D for ; Wed, 11 Sep 2024 12:37:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMYY-0000Zw-U6; Wed, 11 Sep 2024 08:34:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYA-0007Sn-HG for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMY8-00016A-R3 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058060; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hs8UEmOhjZhsT4bHEFTB4w8fw7ILBNMs3ZZtiuWZjhk=; b=SymLhN/l8B+YEyXVXMZHWZWndRgPPryPiMHYHLYQ2+YAGs+F19Sz6WiFuTRcgP7McCMSG5 BH9M2iXPyZkwZV2rBE34AXBnrKv+xm09liJC4rBRx1UBb8rYan5cnEAuEJRW/9DIdxgC6e ryx2opp0vo/evD8SbcSgIATMT/rZobY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-ctsUU7D-OEKb0EgCklHc6Q-1; Wed, 11 Sep 2024 08:34:18 -0400 X-MC-Unique: ctsUU7D-OEKb0EgCklHc6Q-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-42cb0ed9072so37261775e9.1 for ; Wed, 11 Sep 2024 05:34:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058056; x=1726662856; 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=hs8UEmOhjZhsT4bHEFTB4w8fw7ILBNMs3ZZtiuWZjhk=; b=XDy6EtAJHc4ToXdGgOWH4pQ7tISexVlx33AerLGyJvpGxiwhcoytXdcqK02bnu2dKX HaKpY9bq4J/eZCzCwp/F8vfkwNIXuX0NySBcTsKiTZTPg8IngnyNWeCraDbs12xkzfRk XyFdZe7aaEEcppzYtBHG78at+s6XbW5LZHotQyglfWpUdzcSkXlpLO2E+q2UuMqYOwgz xZxA09b1AVDVk3iHql8XB2vNZB60Tu/26OJKFLkXCUTH/0mBeAjqDYcgTc+nIeea5lln o7kC8oslfXBDNhA3peG3KuUEl4lEZmglVosGeDfjrrweCtbpgp6hX4+QmGGmnoWSoo0M 7DzA== X-Gm-Message-State: AOJu0Ywd44SVWFZ/zHGl4vp+0fwPBt2nvC+I2f2UhUky6AVTZUVrWNRl 2W+iTIdzzgr7OGnokrtruWhiOOjdKkTFi//AffhFK3b3p5ozrp1hIenwrJqxs3i45LClSZ4fN3r gfKmR2qm6eKRq5oolYAAe8lSVz4QtasmhCH4I/IO5dg/5srfGej1A8VhIR4fLlj0Xd3+LDsJAS0 7x25W6L/TrkB4cbS1SUDqPKJcVXD5l3I1mTx6WEns= X-Received: by 2002:a7b:ce88:0:b0:42c:b5a6:69bd with SMTP id 5b1f17b1804b1-42cb5a66a1bmr110846955e9.30.1726058056092; Wed, 11 Sep 2024 05:34:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFblVRHWzCmeAHkkx+rNUIyfCodyCiWqadaArE3l2Kzb8cyVFAv7/F7oJOuz01wEQ6Wvhsb8g== X-Received: by 2002:a7b:ce88:0:b0:42c:b5a6:69bd with SMTP id 5b1f17b1804b1-42cb5a66a1bmr110846665e9.30.1726058055506; Wed, 11 Sep 2024 05:34:15 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956ddaf3sm11490519f8f.96.2024.09.11.05.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ani Sinha Subject: [PULL 10/17] kvm/i386: replace identity_base variable with a constant Date: Wed, 11 Sep 2024 14:33:35 +0200 Message-ID: <20240911123342.339482-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org identity_base variable is first initialzied to address 0xfffbc000 and then kvm_vm_set_identity_map_addr() overrides this value to address 0xfeffc000. The initial address to which the variable was initialized was never used. Clean everything up, placing 0xfeffc000 in a preprocessor constant. Reported-by: Ani Sinha Signed-off-by: Paolo Bonzini --- target/i386/kvm/kvm.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 599faf0ac6e..5422fd7fa7d 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -81,6 +81,16 @@ do { } while (0) #endif +/* + * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code directly. + * In order to use vm86 mode, an EPT identity map and a TSS are needed. + * Since these must be part of guest physical memory, we need to allocate + * them, both by setting their start addresses in the kernel and by + * creating a corresponding e820 entry. We need 4 pages before the BIOS, + * so this value allows up to 16M BIOSes. + */ +#define KVM_IDENTITY_BASE 0xfeffc000 + /* From arch/x86/kvm/lapic.h */ #define KVM_APIC_BUS_CYCLE_NS 1 #define KVM_APIC_BUS_FREQUENCY (1000000000ULL / KVM_APIC_BUS_CYCLE_NS) @@ -3036,18 +3046,9 @@ static int kvm_vm_enable_triple_fault_event(KVMState *s) return ret; } -static int kvm_vm_set_identity_map_addr(KVMState *s, uint64_t *identity_base) +static int kvm_vm_set_identity_map_addr(KVMState *s, uint64_t identity_base) { - /* - * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code directly. - * In order to use vm86 mode, an EPT identity map and a TSS are needed. - * Since these must be part of guest physical memory, we need to allocate - * them, both by setting their start addresses in the kernel and by - * creating a corresponding e820 entry. We need 4 pages before the BIOS, - * so this value allows up to 16M BIOSes. - */ - *identity_base = 0xfeffc000; - return kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, identity_base); + return kvm_vm_ioctl(s, KVM_SET_IDENTITY_MAP_ADDR, &identity_base); } static int kvm_vm_set_nr_mmu_pages(KVMState *s) @@ -3064,10 +3065,9 @@ static int kvm_vm_set_nr_mmu_pages(KVMState *s) return ret; } -static int kvm_vm_set_tss_addr(KVMState *s, uint64_t identity_base) +static int kvm_vm_set_tss_addr(KVMState *s, uint64_t tss_base) { - /* Set TSS base one page after EPT identity map. */ - return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, identity_base); + return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, tss_base); } static int kvm_vm_enable_disable_exits(KVMState *s) @@ -3195,7 +3195,6 @@ static void kvm_vm_enable_energy_msrs(KVMState *s) int kvm_arch_init(MachineState *ms, KVMState *s) { - uint64_t identity_base = 0xfffbc000; int ret; struct utsname utsname; Error *local_err = NULL; @@ -3263,18 +3262,19 @@ int kvm_arch_init(MachineState *ms, KVMState *s) uname(&utsname); lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0; - ret = kvm_vm_set_identity_map_addr(s, &identity_base); + ret = kvm_vm_set_identity_map_addr(s, KVM_IDENTITY_BASE); if (ret < 0) { return ret; } - ret = kvm_vm_set_tss_addr(s, identity_base + 0x1000); + /* Set TSS base one page after EPT identity map. */ + ret = kvm_vm_set_tss_addr(s, KVM_IDENTITY_BASE + 0x1000); if (ret < 0) { return ret; } /* Tell fw_cfg to notify the BIOS to reserve the range. */ - e820_add_entry(identity_base, 0x4000, E820_RESERVED); + e820_add_entry(KVM_IDENTITY_BASE, 0x4000, E820_RESERVED); ret = kvm_vm_set_nr_mmu_pages(s); if (ret < 0) { From patchwork Wed Sep 11 12:33:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79E10EE499F for ; Wed, 11 Sep 2024 12:42:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMYZ-0000hB-Rq; Wed, 11 Sep 2024 08:34:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYB-0007XT-P9 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMY9-00016J-Ur for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gU4vA1l3j7vpb6U9RGVZr3j7o9V0Y0q871++U1XS99U=; b=iWyq6cK4B3Tgix9WnlnoChny3MjXgJdMIakpyUr9tybvHzBoZeAB4QcmKgYFbDSOqXV0sp ze6aOfhb7QoRZu74fExFN2Pb9f2xoLlcB0QqB6+5vZJdpzXOMEHnWhGq4e0IsCaVARahGp kCmACmWE0gCOWe44u4xnQsA25TqY0bM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-WctiAn0ANhyw_cS2vb2miA-1; Wed, 11 Sep 2024 08:34:20 -0400 X-MC-Unique: WctiAn0ANhyw_cS2vb2miA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-42cb6ed7f9dso30852565e9.3 for ; Wed, 11 Sep 2024 05:34:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058059; x=1726662859; 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=gU4vA1l3j7vpb6U9RGVZr3j7o9V0Y0q871++U1XS99U=; b=Ba8PfAu7Ur2/IbYGWDCeo8fvPt31SS4IXdHeEz+isu0Cb4edf0SBhz7a9I2jsPu7zx 6aVHbQG7GPIHcpbDGHEiTgq0wb32cfqB1zIrhq8b4Nn3JD0jfygtFP0GLjRzhVwBr/Wv kINUUBP6F8aUo55gupoGO+bMwCqHOKrZa8UF1VQ4yKrq66Ij67T57+oSVawkjyNi5FzR y0h7EJjQPJGgMruM6D1JTYS5NuGl5HEzI/szL82TcxmM5SiE1V/VnFqR/VwGvObqavwm 9se4oF1Q/RaE1J+4H8PedMnEFFfFx/p4dqtD9nLxkYsazIQJmxsHqudEMAFBJ740l/df sCGA== X-Gm-Message-State: AOJu0YzU9DtWCRhROq900akTSVc8o2ZUL9V+vMgIplIHcZQ7g0jbvJ1u QeFZ8PitRbW4+8P/2rjVO2LO/GyOZ56xBNWbmBC/5xKyD7Ylv7GB6VSW3Vm9A/SdgTbdTIHLgET VROcI5auksN/4gQza2/l4dymvsemdN2Tu/fc0nutLX0lkuFFJjBt+hkyH0Fw4tfZOiOh5QHdjb0 GDMBbrEakkVYY8TnCkXeDLNteN/au0EvQtxdTLeM8= X-Received: by 2002:a5d:4387:0:b0:374:c160:269e with SMTP id ffacd0b85a97d-378922a6d58mr12067515f8f.22.1726058058769; Wed, 11 Sep 2024 05:34:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1syhIqZn9kkdR5trZlf4NlSE5E+KBXO4xNaw8uzj3xmc6XFKG/brCDEo8NOohUZZrfsloHw== X-Received: by 2002:a5d:4387:0:b0:374:c160:269e with SMTP id ffacd0b85a97d-378922a6d58mr12067493f8f.22.1726058058284; Wed, 11 Sep 2024 05:34:18 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3789564aea0sm11454160f8f.20.2024.09.11.05.34.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ani Sinha , pbonzini@redhat.com, zhao1.liu@intel.com Subject: [PULL 11/17] kvm: refactor core virtual machine creation into its own function Date: Wed, 11 Sep 2024 14:33:36 +0200 Message-ID: <20240911123342.339482-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Ani Sinha Refactoring the core logic around KVM_CREATE_VM into its own separate function so that it can be called from other functions in subsequent patches. There is no functional change in this patch. CC: pbonzini@redhat.com CC: zhao1.liu@intel.com Signed-off-by: Ani Sinha Link: https://lore.kernel.org/r/20240808113838.1697366-1-anisinha@redhat.com Signed-off-by: Paolo Bonzini --- accel/kvm/kvm-all.c | 89 ++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 33 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index fcc157f0e60..ebaa632a21e 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2385,6 +2385,60 @@ uint32_t kvm_dirty_ring_size(void) return kvm_state->kvm_dirty_ring_size; } +static int do_kvm_create_vm(MachineState *ms, int type) +{ + KVMState *s; + int ret; + + s = KVM_STATE(ms->accelerator); + + do { + ret = kvm_ioctl(s, KVM_CREATE_VM, type); + } while (ret == -EINTR); + + if (ret < 0) { + error_report("ioctl(KVM_CREATE_VM) failed: %s", strerror(-ret)); + +#ifdef TARGET_S390X + if (ret == -EINVAL) { + error_printf("Host kernel setup problem detected." + " Please verify:\n"); + error_printf("- for kernels supporting the" + " switch_amode or user_mode parameters, whether"); + error_printf(" user space is running in primary address space\n"); + error_printf("- for kernels supporting the vm.allocate_pgste" + " sysctl, whether it is enabled\n"); + } +#elif defined(TARGET_PPC) + if (ret == -EINVAL) { + error_printf("PPC KVM module is not loaded. Try modprobe kvm_%s.\n", + (type == 2) ? "pr" : "hv"); + } +#endif + } + + return ret; +} + +static int find_kvm_machine_type(MachineState *ms) +{ + MachineClass *mc = MACHINE_GET_CLASS(ms); + int type; + + if (object_property_find(OBJECT(current_machine), "kvm-type")) { + g_autofree char *kvm_type; + kvm_type = object_property_get_str(OBJECT(current_machine), + "kvm-type", + &error_abort); + type = mc->kvm_type(ms, kvm_type); + } else if (mc->kvm_type) { + type = mc->kvm_type(ms, NULL); + } else { + type = kvm_arch_get_default_type(ms); + } + return type; +} + static int kvm_init(MachineState *ms) { MachineClass *mc = MACHINE_GET_CLASS(ms); @@ -2467,45 +2521,14 @@ static int kvm_init(MachineState *ms) } s->as = g_new0(struct KVMAs, s->nr_as); - if (object_property_find(OBJECT(current_machine), "kvm-type")) { - g_autofree char *kvm_type = object_property_get_str(OBJECT(current_machine), - "kvm-type", - &error_abort); - type = mc->kvm_type(ms, kvm_type); - } else if (mc->kvm_type) { - type = mc->kvm_type(ms, NULL); - } else { - type = kvm_arch_get_default_type(ms); - } - + type = find_kvm_machine_type(ms); if (type < 0) { ret = -EINVAL; goto err; } - do { - ret = kvm_ioctl(s, KVM_CREATE_VM, type); - } while (ret == -EINTR); - + ret = do_kvm_create_vm(ms, type); if (ret < 0) { - error_report("ioctl(KVM_CREATE_VM) failed: %s", strerror(-ret)); - -#ifdef TARGET_S390X - if (ret == -EINVAL) { - error_printf("Host kernel setup problem detected." - " Please verify:\n"); - error_printf("- for kernels supporting the" - " switch_amode or user_mode parameters, whether"); - error_printf(" user space is running in primary address space\n"); - error_printf("- for kernels supporting the vm.allocate_pgste" - " sysctl, whether it is enabled\n"); - } -#elif defined(TARGET_PPC) - if (ret == -EINVAL) { - error_printf("PPC KVM module is not loaded. Try modprobe kvm_%s.\n", - (type == 2) ? "pr" : "hv"); - } -#endif goto err; } From patchwork Wed Sep 11 12:33:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8588EE499D for ; Wed, 11 Sep 2024 12:37:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMYc-00013t-7m; Wed, 11 Sep 2024 08:34:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYG-0007sL-Uf for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYD-00016Z-Gm for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058064; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UrN7D4tivV0tP1DhJlOSWVjlUhO1d1hy6W2UrVe+mlY=; b=YnZNpg0wqZZ6VojMqzE+OVJLrs7V3+NtidlRmfBBYqY+pYSGOG86iRPYUUdi73ytCXrIk6 MH9A41sKFr9iTNHYeH/4oDNyf9gz+1dXIZYXZz4NCn+VtJXI26YU7dZKwzom/+VK+uxIRr kDsFI0zGMhWI+uexLUHiFRaoUeMhGBI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-33-xhJAdcUZNYqVr7zIFk2Wdg-1; Wed, 11 Sep 2024 08:34:24 -0400 X-MC-Unique: xhJAdcUZNYqVr7zIFk2Wdg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-374c301db60so2872543f8f.2 for ; Wed, 11 Sep 2024 05:34:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058062; x=1726662862; 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=UrN7D4tivV0tP1DhJlOSWVjlUhO1d1hy6W2UrVe+mlY=; b=KGSYDYfQ891U9VqNClG5RBeD5pqFzuj66z4qcD+Fw7uGiqW6Py+rtDrM1buG17zfZI LhAYk/Ji56/gD4bxMLzkbvGBeum/K61OOEE0mWKTfNwBizHTEcEVX8GRigmrQaBvC5g6 lb4Jq2DW43oftZBZevpp7dxfg/EFV1FHePCiwW2ZkXUIQrI/x3W/s/tQCxzPIm8XXKdx IGYIZvxfWxL5+dtHuJqkMmAugbB+bXxreggq0j6JGF7HvtY6nBdGr2i2P+n9NG4nt25x ABURYZH/1CF9BJa224SfmVspj1qO/b6XjZrNUuf9tl8unya7NUgukXJ02uCspIP1OWI7 RO5g== X-Gm-Message-State: AOJu0Yx9Q6+CbudYEry2sHl2XjJsBk3Hg0kBRXBkBT1fh/b+BsItH3kw 1UV5HnfL/RtcTmSjWsRqwxbLmQLHhVdnygkPs29pQ5ycQR/XaePLClMyDlx4xiniy3dUoura4So uVfORiPMPGtB6fq84tFRq+/lml6XM0Z1YbuAoVlqfAjdvU2tSTnhXqT3iBGvvVUILzNI7ylM59V P+kjQ30+VH4ZEMx18JiXpiZQR7cLp5Fu4kTxDGFbM= X-Received: by 2002:a5d:4402:0:b0:371:a70d:107e with SMTP id ffacd0b85a97d-37892685889mr7410250f8f.6.1726058062109; Wed, 11 Sep 2024 05:34:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGc+Xq4e8/dTvEEQA4QDseIOmVkIgTO67keasg7fRv3bfJF66PtEtbBmMN3DrWYzSvO3S6hdw== X-Received: by 2002:a5d:4402:0:b0:371:a70d:107e with SMTP id ffacd0b85a97d-37892685889mr7410228f8f.6.1726058061589; Wed, 11 Sep 2024 05:34:21 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956de0e2sm11439107f8f.105.2024.09.11.05.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Fabian Vogt Subject: [PULL 12/17] target/i386: Expose IBPB-BRTYPE and SBPB CPUID bits to the guest Date: Wed, 11 Sep 2024 14:33:37 +0200 Message-ID: <20240911123342.339482-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Fabiano Rosas According to AMD's Speculative Return Stack Overflow whitepaper (link below), the hypervisor should synthesize the value of IBPB_BRTYPE and SBPB CPUID bits to the guest. Support for this is already present in the kernel with commit e47d86083c66 ("KVM: x86: Add SBPB support") and commit 6f0f23ef76be ("KVM: x86: Add IBPB_BRTYPE support"). Add support in QEMU to expose the bits to the guest OS. host: # cat /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow Mitigation: Safe RET before (guest): $ cpuid -l 0x80000021 -1 -r 0x80000021 0x00: eax=0x00000045 ebx=0x00000000 ecx=0x00000000 edx=0x00000000 ^ $ cat /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow Vulnerable: Safe RET, no microcode after (guest): $ cpuid -l 0x80000021 -1 -r 0x80000021 0x00: eax=0x18000045 ebx=0x00000000 ecx=0x00000000 edx=0x00000000 ^ $ cat /sys/devices/system/cpu/vulnerabilities/spec_rstack_overflow Mitigation: Safe RET Reported-by: Fabian Vogt Link: https://www.amd.com/content/dam/amd/en/documents/corporate/cr/speculative-return-stack-overflow-whitepaper.pdf Signed-off-by: Fabiano Rosas Link: https://lore.kernel.org/r/20240805202041.5936-1-farosas@suse.de Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 31f287cae05..ff227a8c5c8 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1221,8 +1221,8 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, + NULL, NULL, NULL, "sbpb", + "ibpb-brtype", NULL, NULL, NULL, }, .cpuid = { .eax = 0x80000021, .reg = R_EAX, }, .tcg_features = 0, From patchwork Wed Sep 11 12:33:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1076BEE49A1 for ; Wed, 11 Sep 2024 12:37:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMYu-0001uQ-AP; Wed, 11 Sep 2024 08:35:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYI-0007wq-5L for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYG-00016k-Nh for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=17siYepaBs4jlr+3C5TgSD76bTlJ6Yu84QzvJEZ1NYE=; b=CCUS5VPDhjshzlTBLSv2apDvNLXYju2oc6AlJwSCYfuxaUCzRUH2NN7xQwbTRyQICvZEqN kP6rXJzma0MHhlzpZFOcsb5wyPJM2d5Hqbp8bQAsHOFvJ2UzkIry4zGLC8kIkyd6QsopN2 EGAV5/fxgK0iIDi+LCz6dJaoLITC/n0= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-331-dd2eRQYtOYG9IjXOOEmscg-1; Wed, 11 Sep 2024 08:34:26 -0400 X-MC-Unique: dd2eRQYtOYG9IjXOOEmscg-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-42cb940cd67so28466515e9.0 for ; Wed, 11 Sep 2024 05:34:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058065; x=1726662865; 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=17siYepaBs4jlr+3C5TgSD76bTlJ6Yu84QzvJEZ1NYE=; b=iCpadWS33W6wq5hBszYvoJWeF4HG9AT4xI42Lgz6aeW2d8Z5wl5gWKOieDfHXcN21T FLu8K4ONrFSzimtocCtkkuZSUgztUFT4TiOBW+V/MsNEN11nomm6SDscyKTrUJWVP2MQ 617szx5NexUyNCxB+XOy2UR4lJHN3o4KTTcB+w1iSkVU7NrGfrgKu7FwWvHbUsfngHXS 2vrKt/rVx2lwr81Xl236yQDoKIrMlpfF7bZ+d5BMpLH2axVKcqlTysvCI61sfRepNjga femTvkGUiUiX+MLLV27ZEl0rJuhu0VMB4yxeYM0F1bNTmbDZw8uqxq/EBH6WiIKM0Y/F Kq5w== X-Gm-Message-State: AOJu0Yytzx6x3y6KemfodR/wokUKSAYzHWSatECqWLTYLlXb0+RAaOfA Mh+9LrNuatwuYe97Gu+Um6s6OaKW2VALmjpscqMiy/n/AVJZdfAh/AP4qAHD5Kccn29aq8kVA78 K/qA1g/+ASMcw+6ltcffeNUpp2CabcEJozhZK1Fz+kTDl4jTf+V2so8CdzC/dRRVgtyjMQwTNfp DX88zH6FXpk42DWbuHUBtrjOR6L9WxtQE3ZAUVIgw= X-Received: by 2002:a05:600c:3506:b0:42c:bd27:4c1e with SMTP id 5b1f17b1804b1-42cbd274fe7mr67775045e9.27.1726058064790; Wed, 11 Sep 2024 05:34:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF08JL7keR6yeoJa/jtcHOElEIm+90qFzGewLwcMZqJUa/Hlw8eznm7WvMbMmKOtK5vthJsWA== X-Received: by 2002:a05:600c:3506:b0:42c:bd27:4c1e with SMTP id 5b1f17b1804b1-42cbd274fe7mr67774755e9.27.1726058064290; Wed, 11 Sep 2024 05:34:24 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895675b8bsm11491987f8f.54.2024.09.11.05.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Bernhard Beschow , Mark Cave-Ayland Subject: [PULL 13/17] hw: Remove unused inclusion of hw/char/serial.h Date: Wed, 11 Sep 2024 14:33:38 +0200 Message-ID: <20240911123342.339482-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Bernhard Beschow Reviewed-by: Mark Cave-Ayland Signed-off-by: Bernhard Beschow Link: https://lore.kernel.org/r/20240905073832.16222-2-shentey@gmail.com Signed-off-by: Paolo Bonzini --- hw/char/riscv_htif.c | 1 - hw/ppc/prep.c | 1 - hw/riscv/sifive_e.c | 1 - hw/riscv/sifive_u.c | 1 - 4 files changed, 4 deletions(-) diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c index 9bef60def1b..54fd55c3e6f 100644 --- a/hw/char/riscv_htif.c +++ b/hw/char/riscv_htif.c @@ -24,7 +24,6 @@ #include "qapi/error.h" #include "qemu/log.h" #include "hw/char/riscv_htif.h" -#include "hw/char/serial.h" #include "chardev/char.h" #include "chardev/char-fe.h" #include "qemu/timer.h" diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index 4eb54770690..fb58c312acc 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -25,7 +25,6 @@ #include "qemu/osdep.h" #include "hw/rtc/m48t59.h" -#include "hw/char/serial.h" #include "hw/block/fdc.h" #include "net/net.h" #include "hw/isa/isa.h" diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c index 87d9602383a..5a1959f2a9e 100644 --- a/hw/riscv/sifive_e.c +++ b/hw/riscv/sifive_e.c @@ -35,7 +35,6 @@ #include "hw/boards.h" #include "hw/loader.h" #include "hw/sysbus.h" -#include "hw/char/serial.h" #include "hw/misc/unimp.h" #include "target/riscv/cpu.h" #include "hw/riscv/riscv_hart.h" diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index af5f923f541..efc8443c844 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -43,7 +43,6 @@ #include "hw/irq.h" #include "hw/loader.h" #include "hw/sysbus.h" -#include "hw/char/serial.h" #include "hw/cpu/cluster.h" #include "hw/misc/unimp.h" #include "hw/sd/sd.h" From patchwork Wed Sep 11 12:33:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 69CDEEE499D for ; Wed, 11 Sep 2024 12:38:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMYc-00011s-3a; Wed, 11 Sep 2024 08:34:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYO-0008L4-P1 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYL-000171-FW for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q5TPiqoqswcpW5f0ntCYsHT0hpanWg27anpDw5EcIfg=; b=dxqISCihqN2zRmt8sobTVlsPTKCMdM/bAd0M0Wcm0GrNxr2DeSoBLZzfC7opBrwoNAGrTl 5R85QYIqMTClP4QZ3FebwYhlpc/LGhmqcpTAUAWMFVOPHWYbjGj+1i+i038X/YDcVf9l64 4awe69TgY5zUOFAqyKm5VzQg0C9xbBU= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-eesWlWAAMDmMhsL6PyfTsg-1; Wed, 11 Sep 2024 08:34:30 -0400 X-MC-Unique: eesWlWAAMDmMhsL6PyfTsg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42cb2c5d634so29110735e9.0 for ; Wed, 11 Sep 2024 05:34:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058068; x=1726662868; 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=Q5TPiqoqswcpW5f0ntCYsHT0hpanWg27anpDw5EcIfg=; b=kEsem6J0xOAmQSL9R9iSTl3Hpm2qy7jUdgirJLM33NuaJUNqScOESiSBhFyZm81/Vo QY6VT7chQiE9b2IXuvAqA3VeYegr+oQEs7REBiXgZOxesRE5zonVzI3NRDk8FN1y3an/ zByqczz2JIKRUnExKtzxjXkKzWMIDS3x8reXuDWtBhZA+QucySukAvT73aOwhMu4LK26 jsztsYuX84FNoZICnwkKDJssavYd02D28F+vtl+Kj182RIgYi9QzjDUZtsF6uNn3KFqv EF5HszqAJ1PyJNKNqAOTtC3fVan0P8wq9MGMTMpPXQ/7yZr4oyJ/BLaDeTN0xkQqpBKs vpKg== X-Gm-Message-State: AOJu0Yzcq5eSHT0HgUFPjqSx1pjwBh/i/I/7BQZrbvUZULZSU847hdnx XF4ctcHU0rGm97VV8XNI+o55CG9Zuui2fqdB7nYp6tYVhscBaoJvMyK62S8dZ+jlDEcGx3jsK2L hRWLCw3zcSkx+Z14yhrojzSaEzIgr9gjlaWCCbpWjbKVph0NRkyqdPhU0+vBCMEUUc3z4y8yzqq apFLFS1YpzRfgPmRxXwaFlGD5IUJwfL9uEhgWekEs= X-Received: by 2002:a05:600c:34ca:b0:42c:b9a0:c17c with SMTP id 5b1f17b1804b1-42cb9a0c52bmr59733385e9.35.1726058067617; Wed, 11 Sep 2024 05:34:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJshuvzk45/tpQ01oZAWmTbwtM2l2Lh2NU6qXc8oe7XPAalBZkRVJ1jTF2n8Xh8UCN24fzHA== X-Received: by 2002:a05:600c:34ca:b0:42c:b9a0:c17c with SMTP id 5b1f17b1804b1-42cb9a0c52bmr59733085e9.35.1726058067059; Wed, 11 Sep 2024 05:34:27 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956de3aesm11427060f8f.110.2024.09.11.05.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Bernhard Beschow , Mark Cave-Ayland Subject: [PULL 14/17] hw/char/serial.h: Extract serial-isa.h Date: Wed, 11 Sep 2024 14:33:39 +0200 Message-ID: <20240911123342.339482-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Bernhard Beschow The includes where updated based on compile errors. Now, the inclusion of the header roughly matches Kconfig dependencies: # grep -r -e "select SERIAL_ISA" hw/ppc/Kconfig: select SERIAL_ISA hw/isa/Kconfig: select SERIAL_ISA hw/sparc64/Kconfig: select SERIAL_ISA hw/i386/Kconfig: select SERIAL_ISA hw/i386/Kconfig: select SERIAL_ISA # for serial_hds_isa_init() Reviewed-by: Mark Cave-Ayland Signed-off-by: Bernhard Beschow Link: https://lore.kernel.org/r/20240905073832.16222-3-shentey@gmail.com Signed-off-by: Paolo Bonzini --- include/hw/char/serial-isa.h | 38 ++++++++++++++++++++++++++++++++++++ include/hw/char/serial.h | 9 --------- hw/char/serial-isa.c | 1 + hw/i386/microvm-dt.c | 2 +- hw/i386/microvm.c | 2 +- hw/i386/pc.c | 2 +- hw/isa/isa-superio.c | 2 +- hw/isa/vt82c686.c | 2 +- hw/ppc/pnv.c | 2 +- hw/sparc64/sun4u.c | 1 + 10 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 include/hw/char/serial-isa.h diff --git a/include/hw/char/serial-isa.h b/include/hw/char/serial-isa.h new file mode 100644 index 00000000000..8517afa128a --- /dev/null +++ b/include/hw/char/serial-isa.h @@ -0,0 +1,38 @@ +/* + * QEMU ISA 16550A UART emulation + * + * Copyright (c) 2003-2004 Fabrice Bellard + * Copyright (c) 2008 Citrix Systems, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef HW_SERIAL_ISA_H +#define HW_SERIAL_ISA_H + +#include "hw/isa/isa.h" + +#define MAX_ISA_SERIAL_PORTS 4 + +#define TYPE_ISA_SERIAL "isa-serial" +void serial_hds_isa_init(ISABus *bus, int from, int to); +void isa_serial_set_iobase(ISADevice *serial, hwaddr iobase); +void isa_serial_set_enabled(ISADevice *serial, bool enabled); + +#endif diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 6e14099ee7f..fca32a532b9 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -106,13 +106,4 @@ SerialMM *serial_mm_init(MemoryRegion *address_space, qemu_irq irq, int baudbase, Chardev *chr, enum device_endian end); -/* serial-isa.c */ - -#define MAX_ISA_SERIAL_PORTS 4 - -#define TYPE_ISA_SERIAL "isa-serial" -void serial_hds_isa_init(ISABus *bus, int from, int to); -void isa_serial_set_iobase(ISADevice *serial, hwaddr iobase); -void isa_serial_set_enabled(ISADevice *serial, bool enabled); - #endif diff --git a/hw/char/serial-isa.c b/hw/char/serial-isa.c index 329b352b9a8..b562ec9d37c 100644 --- a/hw/char/serial-isa.c +++ b/hw/char/serial-isa.c @@ -29,6 +29,7 @@ #include "sysemu/sysemu.h" #include "hw/acpi/acpi_aml_interface.h" #include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "hw/isa/isa.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" diff --git a/hw/i386/microvm-dt.c b/hw/i386/microvm-dt.c index b3049e4f9f2..fc5db6ed7ff 100644 --- a/hw/i386/microvm-dt.c +++ b/hw/i386/microvm-dt.c @@ -34,7 +34,7 @@ #include "qemu/cutils.h" #include "qapi/error.h" #include "sysemu/device_tree.h" -#include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "hw/i386/fw_cfg.h" #include "hw/rtc/mc146818rtc.h" #include "hw/sysbus.h" diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 40edcee7af2..05c882669c2 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -39,7 +39,7 @@ #include "hw/intc/i8259.h" #include "hw/timer/i8254.h" #include "hw/rtc/mc146818rtc.h" -#include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "hw/display/ramfb.h" #include "hw/i386/topology.h" #include "hw/i386/e820_memory_layout.h" diff --git a/hw/i386/pc.c b/hw/i386/pc.c index f4df8637ef0..7fc4d034550 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -25,7 +25,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "hw/i386/pc.h" -#include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "hw/char/parallel.h" #include "hw/hyperv/hv-balloon.h" #include "hw/i386/fw_cfg.h" diff --git a/hw/isa/isa-superio.c b/hw/isa/isa-superio.c index a8c8c58ef7f..cff756e791b 100644 --- a/hw/isa/isa-superio.c +++ b/hw/isa/isa-superio.c @@ -22,7 +22,7 @@ #include "hw/qdev-properties.h" #include "hw/input/i8042.h" #include "hw/char/parallel-isa.h" -#include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "trace.h" static void isa_superio_realize(DeviceState *dev, Error **errp) diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 505b44c4e6b..1aa5c9613fe 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -17,7 +17,7 @@ #include "hw/isa/vt82c686.h" #include "hw/block/fdc.h" #include "hw/char/parallel-isa.h" -#include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "hw/pci/pci.h" #include "hw/qdev-properties.h" #include "hw/ide/pci.h" diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 3526852685b..ffc3f2bca06 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -53,7 +53,7 @@ #include "hw/ppc/pnv_pnor.h" #include "hw/isa/isa.h" -#include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "hw/rtc/mc146818rtc.h" #include diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index 4ece1ac1ffc..a839abbf5d0 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -35,6 +35,7 @@ #include "hw/qdev-properties.h" #include "hw/pci-host/sabre.h" #include "hw/char/serial.h" +#include "hw/char/serial-isa.h" #include "hw/char/parallel-isa.h" #include "hw/rtc/m48t59.h" #include "migration/vmstate.h" From patchwork Wed Sep 11 12:33:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B7998EE499F for ; Wed, 11 Sep 2024 12:39:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMZ1-0002gb-G7; Wed, 11 Sep 2024 08:35:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYS-00008g-4P for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYO-000177-8B for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LHkuky0731oI/nDRu2aiRQJHc/WkWZGbAcZFCyeHcHw=; b=fLg/2esXy2MDq162tDlxDH+oUKIi2xx7xvy1mmjGmKW23E78BVIiJWrdUe2x0yTIMCi1G6 C1fSlTnpvVAaBIAuPdLNty5w8SCm83X6xKM4Aec3HvIzbDKnbWg1MDwQgiO7rbsLIHPJls Hf98MnK9+uYJzEgq8vKmDy5MKG0dZaU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-551-hWNtp6RaNdGiAGD5kHWhVw-1; Wed, 11 Sep 2024 08:34:33 -0400 X-MC-Unique: hWNtp6RaNdGiAGD5kHWhVw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-374c9b0daf3so3352364f8f.1 for ; Wed, 11 Sep 2024 05:34:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058072; x=1726662872; 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=LHkuky0731oI/nDRu2aiRQJHc/WkWZGbAcZFCyeHcHw=; b=i/Xo4L7xj+39JPLX2ul8lwP7/q8V5dacI+teeBbQY+zod42f/2JN0wiQ3nEQfi3Xff HwCtAewVx6PqB/qmoQATFcKpjFknyw4S9LxNkpdCIWV4SxyoaV2kPypJ2Hyjt9LZ3iuW tVRPSOG6RK7izzp+Bg2zTpkr9HRQdE8WE6rMw0oFNOSa/HBcVi/c3+c91NX99z8o0IT1 4mhS6PNuIAaYgnN06Vk/i8atgVco7nzey0yfbcfv505Cn6tdDLpBjgJ3gEIwNRwVcQeU cfL1tJhj/UcF3RjTrTovhABabhhvofdEGArdCRdj92xolq3/29yZHM6aHx+RPfKJDXzn Fc1w== X-Gm-Message-State: AOJu0YzzmNEeQbI07UTwQNrbzGr6uLx95hGUNxuRtZA1XK6+bBKGgpMq 8FLdfTR4ZBWjtwQS2dfQ/vPZIxGijOHL5Q21VoYAtG08+27GrcVdE0qxzf+H/VcMYbuy+gqBsGz K4QLUWB/ENAxakWbHzhHjnWRWb2IvqusC8X/2VlmvpOMvRYIYfBEm9sQ47OmwQ8G/7SvERDIkGD aHWbXqxJOb2vkZcqYuamN2IchLKbAzQR+uucSnOHs= X-Received: by 2002:a5d:6742:0:b0:371:8db9:939e with SMTP id ffacd0b85a97d-37894a6b0aemr9172495f8f.51.1726058071046; Wed, 11 Sep 2024 05:34:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZnVTU8SCa2h1hNzzJTz1gA9T/fXYsu02jORaiSrzDQWbL5i5qMJcuONoyB+x4fmK9kK6fHQ== X-Received: by 2002:a5d:6742:0:b0:371:8db9:939e with SMTP id ffacd0b85a97d-37894a6b0aemr9172463f8f.51.1726058070210; Wed, 11 Sep 2024 05:34:30 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3789564a340sm11459509f8f.24.2024.09.11.05.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Bernhard Beschow , Andrew Jeffery , Mark Cave-Ayland Subject: [PULL 15/17] hw/char: Extract serial-mm Date: Wed, 11 Sep 2024 14:33:40 +0200 Message-ID: <20240911123342.339482-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Bernhard Beschow hw/char/serial currently contains the implementation of both TYPE_SERIAL and TYPE_SERIAL_MM. According to serial_class_init(), TYPE_SERIAL is an internal class while TYPE_SERIAL_MM is used by numerous machine types directly. Let's move the latter into its own module which makes the dependencies more obvious and the code more tidy. The includes and the dependencies have been converted mechanically except in the hw/char directories which were updated manually. The result was compile-tested. Now, only hw/char makes direct use of TYPE_SERIAL: # grep -r -e "select SERIAL" | grep -v SERIAL_ hw/char/Kconfig: select SERIAL hw/char/Kconfig: select SERIAL hw/char/Kconfig: select SERIAL hw/char/Kconfig: select SERIAL hw/char/Kconfig: select SERIAL # grep -r -e "/serial\\.h" include/hw/char/serial-mm.h:#include "hw/char/serial.h" hw/char/serial-pci-multi.c:#include "hw/char/serial.h" hw/char/serial.c:#include "hw/char/serial.h" hw/char/serial-isa.c:#include "hw/char/serial.h" hw/char/serial-pci.c:#include "hw/char/serial.h" Tested-by: Andrew Jeffery Reviewed-by: Mark Cave-Ayland Signed-off-by: Bernhard Beschow Link: https://lore.kernel.org/r/20240905073832.16222-4-shentey@gmail.com Signed-off-by: Paolo Bonzini --- include/hw/arm/aspeed_soc.h | 2 +- include/hw/char/mchp_pfsoc_mmuart.h | 2 +- include/hw/char/serial-mm.h | 52 +++++++++ include/hw/char/serial.h | 19 ---- hw/arm/allwinner-a10.c | 2 +- hw/arm/allwinner-h3.c | 2 +- hw/arm/allwinner-r40.c | 2 +- hw/arm/aspeed_ast2400.c | 2 +- hw/arm/aspeed_soc_common.c | 2 +- hw/arm/kzm.c | 2 +- hw/arm/msf2-soc.c | 2 +- hw/arm/musicpal.c | 2 +- hw/arm/npcm7xx.c | 2 +- hw/arm/pxa2xx.c | 2 +- hw/char/omap_uart.c | 2 +- hw/char/serial-mm.c | 157 ++++++++++++++++++++++++++++ hw/char/serial.c | 126 ---------------------- hw/display/sm501.c | 2 +- hw/hppa/machine.c | 2 +- hw/loongarch/virt.c | 2 +- hw/microblaze/petalogix_ml605_mmu.c | 2 +- hw/mips/boston.c | 2 +- hw/mips/jazz.c | 2 +- hw/mips/loongson3_virt.c | 2 +- hw/mips/malta.c | 2 +- hw/mips/mipssim.c | 2 +- hw/openrisc/openrisc_sim.c | 2 +- hw/openrisc/virt.c | 2 +- hw/ppc/e500.c | 2 +- hw/ppc/ppc405_uc.c | 2 +- hw/ppc/ppc440_bamboo.c | 2 +- hw/ppc/sam460ex.c | 2 +- hw/ppc/virtex_ml507.c | 2 +- hw/riscv/virt.c | 2 +- hw/sparc64/niagara.c | 2 +- hw/sparc64/sun4u.c | 2 +- hw/xtensa/xtfpga.c | 2 +- hw/arm/Kconfig | 20 ++-- hw/char/Kconfig | 4 + hw/char/meson.build | 1 + hw/display/Kconfig | 2 +- hw/hppa/Kconfig | 2 +- hw/loongarch/Kconfig | 2 +- hw/microblaze/Kconfig | 2 +- hw/mips/Kconfig | 10 +- hw/openrisc/Kconfig | 4 +- hw/ppc/Kconfig | 10 +- hw/riscv/Kconfig | 2 +- hw/sparc64/Kconfig | 1 + hw/xtensa/Kconfig | 2 +- 50 files changed, 276 insertions(+), 206 deletions(-) create mode 100644 include/hw/char/serial-mm.h create mode 100644 hw/char/serial-mm.c diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h index 624d489e0d6..689f52dae8f 100644 --- a/include/hw/arm/aspeed_soc.h +++ b/include/hw/arm/aspeed_soc.h @@ -39,7 +39,7 @@ #include "hw/misc/unimp.h" #include "hw/misc/aspeed_peci.h" #include "hw/fsi/aspeed_apb2opb.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/intc/arm_gicv3.h" #define ASPEED_SPIS_NUM 2 diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h index b0e14ca3554..a7b8b1b08b3 100644 --- a/include/hw/char/mchp_pfsoc_mmuart.h +++ b/include/hw/char/mchp_pfsoc_mmuart.h @@ -29,7 +29,7 @@ #define HW_MCHP_PFSOC_MMUART_H #include "hw/sysbus.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #define MCHP_PFSOC_MMUART_REG_COUNT 13 diff --git a/include/hw/char/serial-mm.h b/include/hw/char/serial-mm.h new file mode 100644 index 00000000000..62a8489d694 --- /dev/null +++ b/include/hw/char/serial-mm.h @@ -0,0 +1,52 @@ +/* + * QEMU 16550A UART emulation + * + * Copyright (c) 2003-2004 Fabrice Bellard + * Copyright (c) 2008 Citrix Systems, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef HW_SERIAL_MM_H +#define HW_SERIAL_MM_H + +#include "hw/char/serial.h" +#include "exec/memory.h" +#include "chardev/char.h" +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_SERIAL_MM "serial-mm" +OBJECT_DECLARE_SIMPLE_TYPE(SerialMM, SERIAL_MM) + +struct SerialMM { + SysBusDevice parent; + + SerialState serial; + + uint8_t regshift; + uint8_t endianness; +}; + +SerialMM *serial_mm_init(MemoryRegion *address_space, + hwaddr base, int regshift, + qemu_irq irq, int baudbase, + Chardev *chr, enum device_endian end); + +#endif diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index fca32a532b9..18952e2942b 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -29,8 +29,6 @@ #include "chardev/char-fe.h" #include "exec/memory.h" #include "qemu/fifo8.h" -#include "chardev/char.h" -#include "hw/sysbus.h" #include "qom/object.h" #define UART_FIFO_LENGTH 16 /* 16550A Fifo Length */ @@ -81,15 +79,6 @@ struct SerialState { }; typedef struct SerialState SerialState; -struct SerialMM { - SysBusDevice parent; - - SerialState serial; - - uint8_t regshift; - uint8_t endianness; -}; - extern const VMStateDescription vmstate_serial; extern const MemoryRegionOps serial_io_ops; @@ -98,12 +87,4 @@ void serial_set_frequency(SerialState *s, uint32_t frequency); #define TYPE_SERIAL "serial" OBJECT_DECLARE_SIMPLE_TYPE(SerialState, SERIAL) -#define TYPE_SERIAL_MM "serial-mm" -OBJECT_DECLARE_SIMPLE_TYPE(SerialMM, SERIAL_MM) - -SerialMM *serial_mm_init(MemoryRegion *address_space, - hwaddr base, int regshift, - qemu_irq irq, int baudbase, - Chardev *chr, enum device_endian end); - #endif diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c index 57d5d80159c..08cdff61e46 100644 --- a/hw/arm/allwinner-a10.c +++ b/hw/arm/allwinner-a10.c @@ -18,7 +18,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu/module.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/sysbus.h" #include "hw/arm/allwinner-a10.h" #include "hw/misc/unimp.h" diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c index 6870c3fe963..9bc57cd2666 100644 --- a/hw/arm/allwinner-h3.c +++ b/hw/arm/allwinner-h3.c @@ -24,7 +24,7 @@ #include "qemu/units.h" #include "hw/qdev-core.h" #include "hw/sysbus.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/misc/unimp.h" #include "hw/usb/hcd-ehci.h" #include "hw/loader.h" diff --git a/hw/arm/allwinner-r40.c b/hw/arm/allwinner-r40.c index b8c72021334..ced73009d63 100644 --- a/hw/arm/allwinner-r40.c +++ b/hw/arm/allwinner-r40.c @@ -26,7 +26,7 @@ #include "hw/boards.h" #include "hw/qdev-core.h" #include "hw/sysbus.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/misc/unimp.h" #include "hw/usb/hcd-ehci.h" #include "hw/loader.h" diff --git a/hw/arm/aspeed_ast2400.c b/hw/arm/aspeed_ast2400.c index d1258862075..ecc81ecc79c 100644 --- a/hw/arm/aspeed_ast2400.c +++ b/hw/arm/aspeed_ast2400.c @@ -15,7 +15,7 @@ #include "qapi/error.h" #include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "qemu/module.h" #include "qemu/error-report.h" #include "hw/i2c/aspeed_i2c.h" diff --git a/hw/arm/aspeed_soc_common.c b/hw/arm/aspeed_soc_common.c index 05551461aea..a5ff33c46d7 100644 --- a/hw/arm/aspeed_soc_common.c +++ b/hw/arm/aspeed_soc_common.c @@ -15,7 +15,7 @@ #include "hw/qdev-properties.h" #include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" const char *aspeed_soc_cpu_type(AspeedSoCClass *sc) diff --git a/hw/arm/kzm.c b/hw/arm/kzm.c index 2ccd6f8a768..fbd140e3833 100644 --- a/hw/arm/kzm.c +++ b/hw/arm/kzm.c @@ -22,7 +22,7 @@ #include "exec/address-spaces.h" #include "net/net.h" #include "hw/net/lan9118.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "sysemu/qtest.h" #include "sysemu/sysemu.h" #include "qemu/cutils.h" diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c index a94a10adcca..c4999ebce38 100644 --- a/hw/arm/msf2-soc.c +++ b/hw/arm/msf2-soc.c @@ -26,7 +26,7 @@ #include "qemu/units.h" #include "qapi/error.h" #include "exec/address-spaces.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/arm/msf2-soc.h" #include "hw/misc/unimp.h" #include "hw/qdev-clock.h" diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c index 2020f73a576..940e4437d91 100644 --- a/hw/arm/musicpal.c +++ b/hw/arm/musicpal.c @@ -18,7 +18,7 @@ #include "net/net.h" #include "sysemu/sysemu.h" #include "hw/boards.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "qemu/timer.h" #include "hw/ptimer.h" #include "hw/qdev-properties.h" diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index cb7791301b4..af04c4b7ec4 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -18,7 +18,7 @@ #include "hw/arm/boot.h" #include "hw/arm/npcm7xx.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/loader.h" #include "hw/misc/unimp.h" #include "hw/qdev-clock.h" diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c index 6b2e54473b3..c1448e670ec 100644 --- a/hw/arm/pxa2xx.c +++ b/hw/arm/pxa2xx.c @@ -17,7 +17,7 @@ #include "migration/vmstate.h" #include "hw/arm/pxa.h" #include "sysemu/sysemu.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/i2c/i2c.h" #include "hw/irq.h" #include "hw/qdev-properties.h" diff --git a/hw/char/omap_uart.c b/hw/char/omap_uart.c index c2ef4c137e1..6ec04299960 100644 --- a/hw/char/omap_uart.c +++ b/hw/char/omap_uart.c @@ -20,7 +20,7 @@ #include "qemu/osdep.h" #include "chardev/char.h" #include "hw/arm/omap.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "exec/address-spaces.h" /* UARTs */ diff --git a/hw/char/serial-mm.c b/hw/char/serial-mm.c new file mode 100644 index 00000000000..2f67776b190 --- /dev/null +++ b/hw/char/serial-mm.c @@ -0,0 +1,157 @@ +/* + * QEMU 16550A UART emulation + * + * Copyright (c) 2003-2004 Fabrice Bellard + * Copyright (c) 2008 Citrix Systems, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/char/serial-mm.h" +#include "exec/cpu-common.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" + +static uint64_t serial_mm_read(void *opaque, hwaddr addr, unsigned size) +{ + SerialMM *s = SERIAL_MM(opaque); + return serial_io_ops.read(&s->serial, addr >> s->regshift, 1); +} + +static void serial_mm_write(void *opaque, hwaddr addr, + uint64_t value, unsigned size) +{ + SerialMM *s = SERIAL_MM(opaque); + value &= 255; + serial_io_ops.write(&s->serial, addr >> s->regshift, value, 1); +} + +static const MemoryRegionOps serial_mm_ops[3] = { + [DEVICE_NATIVE_ENDIAN] = { + .read = serial_mm_read, + .write = serial_mm_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .valid.max_access_size = 8, + .impl.max_access_size = 8, + }, + [DEVICE_LITTLE_ENDIAN] = { + .read = serial_mm_read, + .write = serial_mm_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid.max_access_size = 8, + .impl.max_access_size = 8, + }, + [DEVICE_BIG_ENDIAN] = { + .read = serial_mm_read, + .write = serial_mm_write, + .endianness = DEVICE_BIG_ENDIAN, + .valid.max_access_size = 8, + .impl.max_access_size = 8, + }, +}; + +static void serial_mm_realize(DeviceState *dev, Error **errp) +{ + SerialMM *smm = SERIAL_MM(dev); + SerialState *s = &smm->serial; + + if (!qdev_realize(DEVICE(s), NULL, errp)) { + return; + } + + memory_region_init_io(&s->io, OBJECT(dev), + &serial_mm_ops[smm->endianness], smm, "serial", + 8 << smm->regshift); + sysbus_init_mmio(SYS_BUS_DEVICE(smm), &s->io); + sysbus_init_irq(SYS_BUS_DEVICE(smm), &smm->serial.irq); +} + +static const VMStateDescription vmstate_serial_mm = { + .name = "serial", + .version_id = 3, + .minimum_version_id = 2, + .fields = (const VMStateField[]) { + VMSTATE_STRUCT(serial, SerialMM, 0, vmstate_serial, SerialState), + VMSTATE_END_OF_LIST() + } +}; + +SerialMM *serial_mm_init(MemoryRegion *address_space, + hwaddr base, int regshift, + qemu_irq irq, int baudbase, + Chardev *chr, enum device_endian end) +{ + SerialMM *smm = SERIAL_MM(qdev_new(TYPE_SERIAL_MM)); + MemoryRegion *mr; + + qdev_prop_set_uint8(DEVICE(smm), "regshift", regshift); + qdev_prop_set_uint32(DEVICE(smm), "baudbase", baudbase); + qdev_prop_set_chr(DEVICE(smm), "chardev", chr); + qdev_set_legacy_instance_id(DEVICE(smm), base, 2); + qdev_prop_set_uint8(DEVICE(smm), "endianness", end); + sysbus_realize_and_unref(SYS_BUS_DEVICE(smm), &error_fatal); + + sysbus_connect_irq(SYS_BUS_DEVICE(smm), 0, irq); + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(smm), 0); + memory_region_add_subregion(address_space, base, mr); + + return smm; +} + +static void serial_mm_instance_init(Object *o) +{ + SerialMM *smm = SERIAL_MM(o); + + object_initialize_child(o, "serial", &smm->serial, TYPE_SERIAL); + + qdev_alias_all_properties(DEVICE(&smm->serial), o); +} + +static Property serial_mm_properties[] = { + /* + * Set the spacing between adjacent memory-mapped UART registers. + * Each register will be at (1 << regshift) bytes after the previous one. + */ + DEFINE_PROP_UINT8("regshift", SerialMM, regshift, 0), + DEFINE_PROP_UINT8("endianness", SerialMM, endianness, DEVICE_NATIVE_ENDIAN), + DEFINE_PROP_END_OF_LIST(), +}; + +static void serial_mm_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + device_class_set_props(dc, serial_mm_properties); + dc->realize = serial_mm_realize; + dc->vmsd = &vmstate_serial_mm; +} + +static const TypeInfo types[] = { + { + .name = TYPE_SERIAL_MM, + .parent = TYPE_SYS_BUS_DEVICE, + .class_init = serial_mm_class_init, + .instance_init = serial_mm_instance_init, + .instance_size = sizeof(SerialMM), + }, +}; + +DEFINE_TYPES(types) diff --git a/hw/char/serial.c b/hw/char/serial.c index d8b2db50829..1e972950e88 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -996,135 +996,9 @@ static const TypeInfo serial_info = { .class_init = serial_class_init, }; -/* Memory mapped interface */ -static uint64_t serial_mm_read(void *opaque, hwaddr addr, - unsigned size) -{ - SerialMM *s = SERIAL_MM(opaque); - return serial_ioport_read(&s->serial, addr >> s->regshift, 1); -} - -static void serial_mm_write(void *opaque, hwaddr addr, - uint64_t value, unsigned size) -{ - SerialMM *s = SERIAL_MM(opaque); - value &= 255; - serial_ioport_write(&s->serial, addr >> s->regshift, value, 1); -} - -static const MemoryRegionOps serial_mm_ops[3] = { - [DEVICE_NATIVE_ENDIAN] = { - .read = serial_mm_read, - .write = serial_mm_write, - .endianness = DEVICE_NATIVE_ENDIAN, - .valid.max_access_size = 8, - .impl.max_access_size = 8, - }, - [DEVICE_LITTLE_ENDIAN] = { - .read = serial_mm_read, - .write = serial_mm_write, - .endianness = DEVICE_LITTLE_ENDIAN, - .valid.max_access_size = 8, - .impl.max_access_size = 8, - }, - [DEVICE_BIG_ENDIAN] = { - .read = serial_mm_read, - .write = serial_mm_write, - .endianness = DEVICE_BIG_ENDIAN, - .valid.max_access_size = 8, - .impl.max_access_size = 8, - }, -}; - -static void serial_mm_realize(DeviceState *dev, Error **errp) -{ - SerialMM *smm = SERIAL_MM(dev); - SerialState *s = &smm->serial; - - if (!qdev_realize(DEVICE(s), NULL, errp)) { - return; - } - - memory_region_init_io(&s->io, OBJECT(dev), - &serial_mm_ops[smm->endianness], smm, "serial", - 8 << smm->regshift); - sysbus_init_mmio(SYS_BUS_DEVICE(smm), &s->io); - sysbus_init_irq(SYS_BUS_DEVICE(smm), &smm->serial.irq); -} - -static const VMStateDescription vmstate_serial_mm = { - .name = "serial", - .version_id = 3, - .minimum_version_id = 2, - .fields = (const VMStateField[]) { - VMSTATE_STRUCT(serial, SerialMM, 0, vmstate_serial, SerialState), - VMSTATE_END_OF_LIST() - } -}; - -SerialMM *serial_mm_init(MemoryRegion *address_space, - hwaddr base, int regshift, - qemu_irq irq, int baudbase, - Chardev *chr, enum device_endian end) -{ - SerialMM *smm = SERIAL_MM(qdev_new(TYPE_SERIAL_MM)); - MemoryRegion *mr; - - qdev_prop_set_uint8(DEVICE(smm), "regshift", regshift); - qdev_prop_set_uint32(DEVICE(smm), "baudbase", baudbase); - qdev_prop_set_chr(DEVICE(smm), "chardev", chr); - qdev_set_legacy_instance_id(DEVICE(smm), base, 2); - qdev_prop_set_uint8(DEVICE(smm), "endianness", end); - sysbus_realize_and_unref(SYS_BUS_DEVICE(smm), &error_fatal); - - sysbus_connect_irq(SYS_BUS_DEVICE(smm), 0, irq); - mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(smm), 0); - memory_region_add_subregion(address_space, base, mr); - - return smm; -} - -static void serial_mm_instance_init(Object *o) -{ - SerialMM *smm = SERIAL_MM(o); - - object_initialize_child(o, "serial", &smm->serial, TYPE_SERIAL); - - qdev_alias_all_properties(DEVICE(&smm->serial), o); -} - -static Property serial_mm_properties[] = { - /* - * Set the spacing between adjacent memory-mapped UART registers. - * Each register will be at (1 << regshift) bytes after the - * previous one. - */ - DEFINE_PROP_UINT8("regshift", SerialMM, regshift, 0), - DEFINE_PROP_UINT8("endianness", SerialMM, endianness, DEVICE_NATIVE_ENDIAN), - DEFINE_PROP_END_OF_LIST(), -}; - -static void serial_mm_class_init(ObjectClass *oc, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(oc); - - device_class_set_props(dc, serial_mm_properties); - dc->realize = serial_mm_realize; - dc->vmsd = &vmstate_serial_mm; -} - -static const TypeInfo serial_mm_info = { - .name = TYPE_SERIAL_MM, - .parent = TYPE_SYS_BUS_DEVICE, - .class_init = serial_mm_class_init, - .instance_init = serial_mm_instance_init, - .instance_size = sizeof(SerialMM), -}; - static void serial_register_types(void) { type_register_static(&serial_info); - type_register_static(&serial_mm_info); } type_init(serial_register_types) diff --git a/hw/display/sm501.c b/hw/display/sm501.c index 26dc8170d89..ad47fb60104 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -29,7 +29,7 @@ #include "qemu/log.h" #include "qemu/module.h" #include "hw/usb/hcd-ohci.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "ui/console.h" #include "hw/sysbus.h" #include "migration/vmstate.h" diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index 5d0a8739deb..0ab54b06762 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -17,7 +17,7 @@ #include "sysemu/runstate.h" #include "hw/rtc/mc146818rtc.h" #include "hw/timer/i8254.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/char/parallel.h" #include "hw/intc/i8259.h" #include "hw/input/lasips2.h" diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c index 29040422aa8..e3a6a252be2 100644 --- a/hw/loongarch/virt.c +++ b/hw/loongarch/virt.c @@ -9,7 +9,7 @@ #include "qemu/datadir.h" #include "qapi/error.h" #include "hw/boards.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "sysemu/kvm.h" #include "sysemu/tcg.h" #include "sysemu/sysemu.h" diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c index 0f5fabc32e3..b4183c5267d 100644 --- a/hw/microblaze/petalogix_ml605_mmu.c +++ b/hw/microblaze/petalogix_ml605_mmu.c @@ -34,7 +34,7 @@ #include "hw/block/flash.h" #include "sysemu/sysemu.h" #include "hw/boards.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/qdev-properties.h" #include "exec/address-spaces.h" #include "hw/ssi/ssi.h" diff --git a/hw/mips/boston.c b/hw/mips/boston.c index 1b44fb354c4..1ced1e337aa 100644 --- a/hw/mips/boston.c +++ b/hw/mips/boston.c @@ -22,7 +22,7 @@ #include "elf.h" #include "hw/boards.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/ide/pci.h" #include "hw/ide/ahci-pci.h" #include "hw/loader.h" diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c index 1bc17e69d3a..a3b39c86633 100644 --- a/hw/mips/jazz.c +++ b/hw/mips/jazz.c @@ -28,7 +28,7 @@ #include "hw/mips/mips.h" #include "hw/intc/i8259.h" #include "hw/dma/i8257.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/char/parallel.h" #include "hw/isa/isa.h" #include "hw/block/fdc.h" diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c index 2067b4fecb5..a2db98665df 100644 --- a/hw/mips/loongson3_virt.c +++ b/hw/mips/loongson3_virt.c @@ -29,7 +29,7 @@ #include "qemu/datadir.h" #include "qapi/error.h" #include "elf.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/intc/loongson_liointc.h" #include "hw/mips/mips.h" #include "hw/mips/fw_cfg.h" diff --git a/hw/mips/malta.c b/hw/mips/malta.c index 664a2ae0a9e..1df00c4bf99 100644 --- a/hw/mips/malta.c +++ b/hw/mips/malta.c @@ -31,7 +31,7 @@ #include "hw/clock.h" #include "hw/southbridge/piix.h" #include "hw/isa/superio.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "net/net.h" #include "hw/boards.h" #include "hw/i2c/smbus_eeprom.h" diff --git a/hw/mips/mipssim.c b/hw/mips/mipssim.c index 9170d6c474b..a07732d3dc5 100644 --- a/hw/mips/mipssim.c +++ b/hw/mips/mipssim.c @@ -31,7 +31,7 @@ #include "exec/address-spaces.h" #include "hw/clock.h" #include "hw/mips/mips.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "net/net.h" #include "sysemu/sysemu.h" #include "hw/boards.h" diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c index bffd6f721f7..9fb63515ef1 100644 --- a/hw/openrisc/openrisc_sim.c +++ b/hw/openrisc/openrisc_sim.c @@ -24,7 +24,7 @@ #include "cpu.h" #include "hw/irq.h" #include "hw/boards.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "net/net.h" #include "hw/openrisc/boot.h" #include "hw/qdev-properties.h" diff --git a/hw/openrisc/virt.c b/hw/openrisc/virt.c index f8a68a6a6b1..47d2c9bd3c7 100644 --- a/hw/openrisc/virt.c +++ b/hw/openrisc/virt.c @@ -14,7 +14,7 @@ #include "exec/address-spaces.h" #include "hw/irq.h" #include "hw/boards.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/core/split-irq.h" #include "hw/openrisc/boot.h" #include "hw/misc/sifive_test.h" diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 3bd12b54ab9..b760c6d6a25 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -24,7 +24,7 @@ #include "net/net.h" #include "qemu/config-file.h" #include "hw/block/flash.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/pci/pci.h" #include "sysemu/block-backend-io.h" #include "sysemu/sysemu.h" diff --git a/hw/ppc/ppc405_uc.c b/hw/ppc/ppc405_uc.c index 0cc68178adf..36b18d66948 100644 --- a/hw/ppc/ppc405_uc.c +++ b/hw/ppc/ppc405_uc.c @@ -32,7 +32,7 @@ #include "hw/irq.h" #include "hw/qdev-properties.h" #include "ppc405.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "qemu/timer.h" #include "sysemu/reset.h" #include "sysemu/sysemu.h" diff --git a/hw/ppc/ppc440_bamboo.c b/hw/ppc/ppc440_bamboo.c index 73f80cf7065..96d9ce65c26 100644 --- a/hw/ppc/ppc440_bamboo.c +++ b/hw/ppc/ppc440_bamboo.c @@ -23,7 +23,7 @@ #include "sysemu/device_tree.h" #include "hw/loader.h" #include "elf.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/ppc/ppc.h" #include "hw/pci-host/ppc4xx.h" #include "sysemu/sysemu.h" diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c index 8dc75fb9f08..1fce093ac8a 100644 --- a/hw/ppc/sam460ex.c +++ b/hw/ppc/sam460ex.c @@ -31,7 +31,7 @@ #include "sysemu/sysemu.h" #include "sysemu/reset.h" #include "hw/sysbus.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/i2c/ppc4xx_i2c.h" #include "hw/i2c/smbus_eeprom.h" #include "hw/ide/pci.h" diff --git a/hw/ppc/virtex_ml507.c b/hw/ppc/virtex_ml507.c index c49da1f46f7..235281e9392 100644 --- a/hw/ppc/virtex_ml507.c +++ b/hw/ppc/virtex_ml507.c @@ -28,7 +28,7 @@ #include "exec/page-protection.h" #include "cpu.h" #include "hw/sysbus.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/block/flash.h" #include "sysemu/sysemu.h" #include "sysemu/reset.h" diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index cef41c150aa..105c20a5ff9 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -27,7 +27,7 @@ #include "hw/loader.h" #include "hw/sysbus.h" #include "hw/qdev-properties.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "target/riscv/cpu.h" #include "hw/core/sysbus-fdt.h" #include "target/riscv/pmu.h" diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c index ab3c4ec3463..67ec403e1d4 100644 --- a/hw/sparc64/niagara.c +++ b/hw/sparc64/niagara.c @@ -27,7 +27,7 @@ #include "qemu/units.h" #include "cpu.h" #include "hw/boards.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "hw/misc/unimp.h" #include "hw/loader.h" #include "hw/sparc/sparc64.h" diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c index a839abbf5d0..541c7f74fa0 100644 --- a/hw/sparc64/sun4u.c +++ b/hw/sparc64/sun4u.c @@ -34,8 +34,8 @@ #include "hw/pci/pci_host.h" #include "hw/qdev-properties.h" #include "hw/pci-host/sabre.h" -#include "hw/char/serial.h" #include "hw/char/serial-isa.h" +#include "hw/char/serial-mm.h" #include "hw/char/parallel-isa.h" #include "hw/rtc/m48t59.h" #include "migration/vmstate.h" diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c index 955e8867a36..45b29d3b4e8 100644 --- a/hw/xtensa/xtfpga.c +++ b/hw/xtensa/xtfpga.c @@ -35,7 +35,7 @@ #include "hw/qdev-properties.h" #include "elf.h" #include "exec/memory.h" -#include "hw/char/serial.h" +#include "hw/char/serial-mm.h" #include "net/net.h" #include "hw/sysbus.h" #include "hw/block/flash.h" diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 1ad60da7aa2..ecde52f4a4a 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -136,7 +136,7 @@ config MUSICPAL select MARVELL_88W8618 select PTIMER select PFLASH_CFI02 - select SERIAL + select SERIAL_MM select WM8750 config NETDUINO2 @@ -179,13 +179,13 @@ config OMAP select NAND select PFLASH_CFI01 select SD - select SERIAL + select SERIAL_MM config PXA2XX bool select FRAMEBUFFER select I2C - select SERIAL + select SERIAL_MM select SD select SSI select USB_OHCI_SYSBUS @@ -399,7 +399,7 @@ config ALLWINNER_A10 select ALLWINNER_EMAC select ALLWINNER_I2C select AXP2XX_PMU - select SERIAL + select SERIAL_MM select UNIMP select USB_OHCI_SYSBUS @@ -411,7 +411,7 @@ config ALLWINNER_H3 select ALLWINNER_SUN8I_EMAC select ALLWINNER_I2C select ALLWINNER_WDT - select SERIAL + select SERIAL_MM select ARM_TIMER select ARM_GIC select UNIMP @@ -427,7 +427,7 @@ config ALLWINNER_R40 select ALLWINNER_A10_PIT select ALLWINNER_WDT select AXP2XX_PMU - select SERIAL + select SERIAL_MM select ARM_TIMER select ARM_GIC select UNIMP @@ -542,7 +542,7 @@ config NPCM7XX select ISL_PMBUS_VR select PL310 # cache controller select PMBUS - select SERIAL + select SERIAL_MM select SSI select UNIMP select PCA954X @@ -564,7 +564,7 @@ config FSL_IMX31 default y depends on TCG && ARM imply I2C_DEVICES - select SERIAL + select SERIAL_MM select IMX select IMX_I2C select WDT_IMX2 @@ -593,7 +593,7 @@ config ASPEED_SOC select I2C select DPS310 select PCA9552 - select SERIAL + select SERIAL_MM select SMBUS_EEPROM select PCA954X select SSI @@ -681,7 +681,7 @@ config MSF2 bool select ARM_V7M select PTIMER - select SERIAL + select SERIAL_MM select SSI select UNIMP diff --git a/hw/char/Kconfig b/hw/char/Kconfig index 4fd74ea8788..4b73a803bf3 100644 --- a/hw/char/Kconfig +++ b/hw/char/Kconfig @@ -21,6 +21,10 @@ config SERIAL_ISA depends on ISA_BUS select SERIAL +config SERIAL_MM + bool + select SERIAL + config SERIAL_PCI bool default y if PCI_DEVICES diff --git a/hw/char/meson.build b/hw/char/meson.build index e5b13b69580..b99938f756a 100644 --- a/hw/char/meson.build +++ b/hw/char/meson.build @@ -14,6 +14,7 @@ system_ss.add(when: 'CONFIG_PL011', if_true: files('pl011.c')) system_ss.add(when: 'CONFIG_SCLPCONSOLE', if_true: files('sclpconsole.c', 'sclpconsole-lm.c')) system_ss.add(when: 'CONFIG_SERIAL', if_true: files('serial.c')) system_ss.add(when: 'CONFIG_SERIAL_ISA', if_true: files('serial-isa.c')) +system_ss.add(when: 'CONFIG_SERIAL_MM', if_true: files('serial-mm.c')) system_ss.add(when: 'CONFIG_SERIAL_PCI', if_true: files('serial-pci.c')) system_ss.add(when: 'CONFIG_SERIAL_PCI_MULTI', if_true: files('serial-pci-multi.c')) system_ss.add(when: 'CONFIG_SHAKTI_UART', if_true: files('shakti_uart.c')) diff --git a/hw/display/Kconfig b/hw/display/Kconfig index a4552c8ed78..5fde4855e3f 100644 --- a/hw/display/Kconfig +++ b/hw/display/Kconfig @@ -76,7 +76,7 @@ config SM501 bool select I2C select DDC - select SERIAL + select SERIAL_MM select USB_OHCI_SYSBUS config TCX diff --git a/hw/hppa/Kconfig b/hw/hppa/Kconfig index d4d457f4ab4..9312c4294a4 100644 --- a/hw/hppa/Kconfig +++ b/hw/hppa/Kconfig @@ -9,7 +9,7 @@ config HPPA_B160L select ASTRO select DINO select LASI - select SERIAL + select SERIAL_MM select SERIAL_PCI select ISA_BUS select I8259 diff --git a/hw/loongarch/Kconfig b/hw/loongarch/Kconfig index 0de713a439e..6b67b34b7a6 100644 --- a/hw/loongarch/Kconfig +++ b/hw/loongarch/Kconfig @@ -9,7 +9,7 @@ config LOONGARCH_VIRT imply PCI_DEVICES imply NVDIMM imply TPM_TIS_SYSBUS - select SERIAL + select SERIAL_MM select VIRTIO_PCI select PLATFORM_BUS select LOONGARCH_IPI diff --git a/hw/microblaze/Kconfig b/hw/microblaze/Kconfig index d78ba843fac..b0214b2c8b2 100644 --- a/hw/microblaze/Kconfig +++ b/hw/microblaze/Kconfig @@ -13,7 +13,7 @@ config PETALOGIX_ML605 default y depends on MICROBLAZE select PFLASH_CFI01 - select SERIAL + select SERIAL_MM select SSI_M25P80 select XILINX select XILINX_AXI diff --git a/hw/mips/Kconfig b/hw/mips/Kconfig index 692bede538e..b09c89a0175 100644 --- a/hw/mips/Kconfig +++ b/hw/mips/Kconfig @@ -10,14 +10,14 @@ config MALTA select MIPS_CPS select PIIX select PFLASH_CFI01 - select SERIAL + select SERIAL_MM select SMBUS_EEPROM config MIPSSIM bool default y depends on MIPS - select SERIAL + select SERIAL_MM select MIPSNET config JAZZ @@ -37,7 +37,7 @@ config JAZZ select FDC_SYSBUS select MC146818RTC select PCKBD - select SERIAL + select SERIAL_MM select PARALLEL select DS1225Y select JAZZ_LED @@ -65,7 +65,7 @@ config LOONGSON3V imply VIRTIO_VGA imply QXL if SPICE imply USB_OHCI_PCI - select SERIAL + select SERIAL_MM select GOLDFISH_RTC select LOONGSON_IPI select LOONGSON_LIOINTC @@ -89,7 +89,7 @@ config MIPS_BOSTON select MIPS_CPS select PCI_EXPRESS_XILINX select AHCI_ICH9 - select SERIAL + select SERIAL_MM config FW_CFG_MIPS bool diff --git a/hw/openrisc/Kconfig b/hw/openrisc/Kconfig index 76b953c62c2..0702f622a55 100644 --- a/hw/openrisc/Kconfig +++ b/hw/openrisc/Kconfig @@ -3,7 +3,7 @@ config OR1K_SIM default y depends on OPENRISC select DEVICE_TREE - select SERIAL + select SERIAL_MM select OPENCORES_ETH select OMPIC select SPLIT_IRQ @@ -19,6 +19,6 @@ config OR1K_VIRT select PCI select PCI_EXPRESS_GENERIC_BRIDGE select GOLDFISH_RTC - select SERIAL + select SERIAL_MM select SIFIVE_TEST select VIRTIO_MMIO diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig index 5addad11240..b44d91bebb2 100644 --- a/hw/ppc/Kconfig +++ b/hw/ppc/Kconfig @@ -51,7 +51,7 @@ config PPC405 select M48T59 select PFLASH_CFI02 select PPC4XX - select SERIAL + select SERIAL_MM config PPC440 bool @@ -63,7 +63,7 @@ config PPC440 select PCI_EXPRESS select PPC440_PCIX select PPC4XX - select SERIAL + select SERIAL_MM select FDT_PPC config PPC4XX @@ -80,7 +80,7 @@ config SAM460EX select IDE_SII3112 select M41T80 select PPC440 - select SERIAL + select SERIAL_MM select SM501 select SMBUS_EEPROM select USB_EHCI_SYSBUS @@ -163,7 +163,7 @@ config E500 select PLATFORM_BUS select PPCE500_PCI select SDHCI - select SERIAL + select SERIAL_MM select MPC_I2C select FDT_PPC select DS1338 @@ -187,7 +187,7 @@ config VIRTEX depends on PPC && FDT select PPC4XX select PFLASH_CFI01 - select SERIAL + select SERIAL_MM select XILINX select XILINX_ETHLITE select FDT_PPC diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index a2030e3a6ff..44695ff9f2c 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -44,7 +44,7 @@ config RISCV_VIRT select PCI select PCI_EXPRESS_GENERIC_BRIDGE select PFLASH_CFI01 - select SERIAL + select SERIAL_MM select RISCV_ACLINT select RISCV_APLIC select RISCV_IMSIC diff --git a/hw/sparc64/Kconfig b/hw/sparc64/Kconfig index 3b948a22907..f764c8a219d 100644 --- a/hw/sparc64/Kconfig +++ b/hw/sparc64/Kconfig @@ -10,6 +10,7 @@ config SUN4U select ISA_BUS select FDC_ISA select SERIAL_ISA + select SERIAL_MM select PCI_SABRE select IDE_CMD646 select PCKBD diff --git a/hw/xtensa/Kconfig b/hw/xtensa/Kconfig index fc5c785cfac..1f0492d89c0 100644 --- a/hw/xtensa/Kconfig +++ b/hw/xtensa/Kconfig @@ -18,4 +18,4 @@ config XTENSA_XTFPGA select DEVICE_TREE select OPENCORES_ETH select PFLASH_CFI01 - select SERIAL + select SERIAL_MM From patchwork Wed Sep 11 12:33:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DFA4BEE499D for ; Wed, 11 Sep 2024 12:40:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMZZ-0004yb-0w; Wed, 11 Sep 2024 08:35:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYZ-0000g8-BP for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYU-00017v-MR for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058082; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EdNzHvrwRr03h8OHjNbvFCAi3J+PoUr9qAAk8R9NyWk=; b=cRxyaNLzLIAcBuCtOjunf9JPHh9sfrP624selnZDJ5+GKKDyd8O05XwtiZ5/hXhlGsHAnr D0EKrEHrHeZjT6sHSHSqILNOEgHuV+1zCH28ZQTyHwxxP1/hqgR5FKMflOE+n/vHxzprbB s2cF+cu+tt3aQUaCXj4Kvi3vpma+HWk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-4EnKIS1vP7WSoSsViXKrTw-1; Wed, 11 Sep 2024 08:34:39 -0400 X-MC-Unique: 4EnKIS1vP7WSoSsViXKrTw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-374c90d24e3so4578673f8f.0 for ; Wed, 11 Sep 2024 05:34:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058078; x=1726662878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EdNzHvrwRr03h8OHjNbvFCAi3J+PoUr9qAAk8R9NyWk=; b=SQcNfw0ZvEkMrnvhGWsCF/c2zNroCxuq62/1GkwwdpVe7ASuDeqHLBRza1Qhxd1QW6 3aVtef26WJUxliejsdxIoTXVmiOlNlNny8q3xb4BHORqjoSIihpIpqcNXkvllQaqMLib ZuSXYEcxpYEwxikkGT0fqqBzsfxj5CrfiPgiHw5AI59hh+J2SNSdQPcC/3+GmV405bft cdy5EGhuN0y6w/hR/t3aqBKtuFowZPXDC3UDr4O903+k921gLEl57jjNn7um4f2Ys74j vi5bqcDneYxpDyvbvnQvrRu5WTOCJnkmKEjfZcQLI9SM/ZEVL4oSw3KiMmhV1UsI24c+ gw5w== X-Gm-Message-State: AOJu0YxJRFCbKBsMH4/deR7qnCygUxGXttE/2vgxj/fWJpTm7z+t5vtG Jr/yVGZnzroa8/QHWMFx4/L9+7zVxThGAEJM52Dh4E/tBOfahVyZ6xAWErfPnDhK4l9waiqM3Qr Jg3RRWG+q5L1vOtvzL2kJ2VRerKC8yH+iXJIEl2k8e/YUAlSxji8ZucjEzF/wVQqIYcFDMTpSy3 uDyUTSfTUpmjtvX5ErNpVdxxyHLA3SntC2cOWT2Vc= X-Received: by 2002:adf:e588:0:b0:374:c69b:5a24 with SMTP id ffacd0b85a97d-37892466727mr13607870f8f.51.1726058076497; Wed, 11 Sep 2024 05:34:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXXFaft+OiA3Gb0R2Y0SgEVhBWI0yDctKdP7wMG/oTG21XWfZcOPVKdWyBjGdRPA6GnL08UQ== X-Received: by 2002:adf:e588:0:b0:374:c69b:5a24 with SMTP id ffacd0b85a97d-37892466727mr13607793f8f.51.1726058074452; Wed, 11 Sep 2024 05:34:34 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d367csm11329359f8f.68.2024.09.11.05.34.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 16/17] virtio-9p: remove virtfs-proxy-helper Date: Wed, 11 Sep 2024 14:33:41 +0200 Message-ID: <20240911123342.339482-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It has been deprecated since 8.1; remove it and suggest using permission mapping or virtiofsd. Signed-off-by: Paolo Bonzini --- MAINTAINERS | 8 - docs/about/deprecated.rst | 23 - docs/about/removed-features.rst | 14 + docs/conf.py | 3 - docs/meson.build | 1 - docs/tools/index.rst | 1 - docs/tools/virtfs-proxy-helper.rst | 75 -- meson.build | 8 - fsdev/qemu-fsdev.h | 1 - hw/9pfs/9p-proxy.h | 101 --- fsdev/qemu-fsdev.c | 19 - fsdev/virtfs-proxy-helper.c | 1193 -------------------------- hw/9pfs/9p-proxy.c | 1279 ---------------------------- fsdev/meson.build | 8 - hw/9pfs/meson.build | 1 - meson_options.txt | 2 - qemu-options.hx | 46 - scripts/meson-buildoptions. | 0 scripts/meson-buildoptions.sh | 4 - 19 files changed, 14 insertions(+), 2773 deletions(-) delete mode 100644 docs/tools/virtfs-proxy-helper.rst delete mode 100644 hw/9pfs/9p-proxy.h delete mode 100644 fsdev/virtfs-proxy-helper.c delete mode 100644 hw/9pfs/9p-proxy.c create mode 100644 scripts/meson-buildoptions. diff --git a/MAINTAINERS b/MAINTAINERS index c14ac014e2d..0a954dc2035 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2258,20 +2258,12 @@ S: Maintained W: https://wiki.qemu.org/Documentation/9p F: hw/9pfs/ X: hw/9pfs/xen-9p* -X: hw/9pfs/9p-proxy* F: fsdev/ -X: fsdev/virtfs-proxy-helper.c F: tests/qtest/virtio-9p-test.c F: tests/qtest/libqos/virtio-9p* T: git https://gitlab.com/gkurz/qemu.git 9p-next T: git https://github.com/cschoenebeck/qemu.git 9p.next -virtio-9p-proxy -F: hw/9pfs/9p-proxy* -F: fsdev/virtfs-proxy-helper.c -F: docs/tools/virtfs-proxy-helper.rst -S: Obsolete - virtio-blk M: Stefan Hajnoczi L: qemu-block@nongnu.org diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 88f0f037865..479d036e094 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -324,29 +324,6 @@ the addition of volatile memory support, it is now necessary to distinguish between persistent and volatile memory backends. As such, memdev is deprecated in favor of persistent-memdev. -``-fsdev proxy`` and ``-virtfs proxy`` (since 8.1) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The 9p ``proxy`` filesystem backend driver has been deprecated and will be -removed (along with its proxy helper daemon) in a future version of QEMU. Please -use ``-fsdev local`` or ``-virtfs local`` for using the 9p ``local`` filesystem -backend, or alternatively consider deploying virtiofsd instead. - -The 9p ``proxy`` backend was originally developed as an alternative to the 9p -``local`` backend. The idea was to enhance security by dispatching actual low -level filesystem operations from 9p server (QEMU process) over to a separate -process (the virtfs-proxy-helper binary). However this alternative never gained -momentum. The proxy backend is much slower than the local backend, hasn't seen -any development in years, and showed to be less secure, especially due to the -fact that its helper daemon must be run as root, whereas with the local backend -QEMU is typically run as unprivileged user and allows to tighten behaviour by -mapping permissions et al by using its 'mapped' security model option. - -Nowadays it would make sense to reimplement the ``proxy`` backend by using -QEMU's ``vhost`` feature, which would eliminate the high latency costs under -which the 9p ``proxy`` backend currently suffers. However as of to date nobody -has indicated plans for such kind of reimplementation unfortunately. - RISC-V 'any' CPU type ``-cpu any`` (since 8.2) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst index fc7b28e6373..b60d1088d24 100644 --- a/docs/about/removed-features.rst +++ b/docs/about/removed-features.rst @@ -517,6 +517,20 @@ The virtio-blk SCSI passthrough feature is a legacy VIRTIO feature. VIRTIO 1.0 and later do not support it because the virtio-scsi device was introduced for full SCSI support. Use virtio-scsi instead when SCSI passthrough is required. +``-fsdev proxy`` and ``-virtfs proxy`` (since 9.2) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The 9p ``proxy`` filesystem backend driver was originally developed to +enhance security by dispatching low level filesystem operations from 9p +server (QEMU process) over to a separate process (the virtfs-proxy-helper +binary). However the proxy backend was much slower than the local backend, +didn't see any development in years, and showed to be less secure, +especially due to the fact that its helper daemon must be run as root. + +Use ``local``, possibly mapping permissions et al by using its 'mapped' +security model option, or switch to ``virtiofs``. The virtiofs daemon +``virtiofsd`` uses vhost to eliminate the high latency costs of the 9p +``proxy`` backend. User-mode emulator command line arguments ----------------------------------------- diff --git a/docs/conf.py b/docs/conf.py index 876f6768815..c11a6ead8a0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -275,9 +275,6 @@ ('tools/qemu-trace-stap', 'qemu-trace-stap', 'QEMU SystemTap trace tool', [], 1), - ('tools/virtfs-proxy-helper', 'virtfs-proxy-helper', - 'QEMU 9p virtfs proxy filesystem helper', - ['M. Mohan Kumar'], 1), ] man_make_section_directory = False diff --git a/docs/meson.build b/docs/meson.build index 322452c8778..3676f81c4d3 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -54,7 +54,6 @@ if build_docs 'qemu-pr-helper.8': (have_tools ? 'man8' : ''), 'qemu-storage-daemon.1': (have_tools ? 'man1' : ''), 'qemu-trace-stap.1': (stap.found() ? 'man1' : ''), - 'virtfs-proxy-helper.1': (have_virtfs_proxy_helper ? 'man1' : ''), 'qemu.1': 'man1', 'qemu-block-drivers.7': 'man7', 'qemu-cpu-models.7': 'man7' diff --git a/docs/tools/index.rst b/docs/tools/index.rst index 33ad438e86f..1e88ae48cdc 100644 --- a/docs/tools/index.rst +++ b/docs/tools/index.rst @@ -15,5 +15,4 @@ command line utilities and other standalone programs. qemu-nbd qemu-pr-helper qemu-trace-stap - virtfs-proxy-helper qemu-vmsr-helper diff --git a/docs/tools/virtfs-proxy-helper.rst b/docs/tools/virtfs-proxy-helper.rst deleted file mode 100644 index bd310ebb07b..00000000000 --- a/docs/tools/virtfs-proxy-helper.rst +++ /dev/null @@ -1,75 +0,0 @@ -QEMU 9p virtfs proxy filesystem helper -====================================== - -Synopsis --------- - -**virtfs-proxy-helper** [*OPTIONS*] - -Description ------------ - -NOTE: The 9p 'proxy' backend is deprecated (since QEMU 8.1) and will be -removed, along with this daemon, in a future version of QEMU! - -Pass-through security model in QEMU 9p server needs root privilege to do -few file operations (like chown, chmod to any mode/uid:gid). There are two -issues in pass-through security model: - -- TOCTTOU vulnerability: Following symbolic links in the server could - provide access to files beyond 9p export path. - -- Running QEMU with root privilege could be a security issue. - -To overcome above issues, following approach is used: A new filesystem -type 'proxy' is introduced. Proxy FS uses chroot + socket combination -for securing the vulnerability known with following symbolic links. -Intention of adding a new filesystem type is to allow qemu to run -in non-root mode, but doing privileged operations using socket IO. - -Proxy helper (a stand alone binary part of qemu) is invoked with -root privileges. Proxy helper chroots into 9p export path and creates -a socket pair or a named socket based on the command line parameter. -QEMU and proxy helper communicate using this socket. QEMU proxy fs -driver sends filesystem request to proxy helper and receives the -response from it. - -The proxy helper is designed so that it can drop root privileges except -for the capabilities needed for doing filesystem operations. - -Options -------- - -The following options are supported: - -.. program:: virtfs-proxy-helper - -.. option:: -h - - Display help and exit - -.. option:: -p, --path PATH - - Path to export for proxy filesystem driver - -.. option:: -f, --fd SOCKET_ID - - Use given file descriptor as socket descriptor for communicating with - qemu proxy fs drier. Usually a helper like libvirt will create - socketpair and pass one of the fds as parameter to this option. - -.. option:: -s, --socket SOCKET_FILE - - Creates named socket file for communicating with qemu proxy fs driver - -.. option:: -u, --uid UID - - uid to give access to named socket file; used in combination with -g. - -.. option:: -g, --gid GID - - gid to give access to named socket file; used in combination with -u. - -.. option:: -n, --nodaemon - - Run as a normal program. By default program will run in daemon mode diff --git a/meson.build b/meson.build index fbda17c987e..56eef434782 100644 --- a/meson.build +++ b/meson.build @@ -2197,13 +2197,6 @@ have_virtfs = get_option('virtfs') \ .disable_auto_if(not have_tools and not have_system) \ .allowed() -have_virtfs_proxy_helper = get_option('virtfs_proxy_helper') \ - .require(host_os != 'darwin', error_message: 'the virtfs proxy helper is incompatible with macOS') \ - .require(have_virtfs, error_message: 'the virtfs proxy helper requires that virtfs is enabled') \ - .disable_auto_if(not have_tools) \ - .require(libcap_ng.found(), error_message: 'the virtfs proxy helper requires libcap-ng') \ - .allowed() - qga_fsfreeze = false qga_fstrim = false if host_os == 'linux' @@ -4397,7 +4390,6 @@ if have_block summary_info += {'Block whitelist (ro)': get_option('block_drv_ro_whitelist')} summary_info += {'Use block whitelist in tools': get_option('block_drv_whitelist_in_tools')} summary_info += {'VirtFS (9P) support': have_virtfs} - summary_info += {'VirtFS (9P) Proxy Helper support (deprecated)': have_virtfs_proxy_helper} summary_info += {'replication support': config_host_data.get('CONFIG_REPLICATION')} summary_info += {'bochs support': get_option('bochs').allowed()} summary_info += {'cloop support': get_option('cloop').allowed()} diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h index 52a53977701..731f1406a81 100644 --- a/fsdev/qemu-fsdev.h +++ b/fsdev/qemu-fsdev.h @@ -18,5 +18,4 @@ int qemu_fsdev_add(QemuOpts *opts, Error **errp); FsDriverEntry *get_fsdev_fsentry(char *id); extern FileOperations local_ops; extern FileOperations synth_ops; -extern FileOperations proxy_ops; #endif diff --git a/hw/9pfs/9p-proxy.h b/hw/9pfs/9p-proxy.h deleted file mode 100644 index 9be4718d3e2..00000000000 --- a/hw/9pfs/9p-proxy.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 9p Proxy callback - * - * Copyright IBM, Corp. 2011 - * - * Authors: - * M. Mohan Kumar - * - * This work is licensed under the terms of the GNU GPL, version 2. See - * the COPYING file in the top-level directory. - */ - -/* - * NOTE: The 9p 'proxy' backend is deprecated (since QEMU 8.1) and will be - * removed in a future version of QEMU! - */ - -#ifndef QEMU_9P_PROXY_H -#define QEMU_9P_PROXY_H - -#define PROXY_MAX_IO_SZ (64 * 1024) -#define V9FS_FD_VALID INT_MAX - -/* - * proxy iovec only support one element and - * marsha/unmarshal doesn't do little endian conversion. - */ -#define proxy_unmarshal(in_sg, offset, fmt, args...) \ - v9fs_iov_unmarshal(in_sg, 1, offset, 0, fmt, ##args) -#define proxy_marshal(out_sg, offset, fmt, args...) \ - v9fs_iov_marshal(out_sg, 1, offset, 0, fmt, ##args) - -union MsgControl { - struct cmsghdr cmsg; - char control[CMSG_SPACE(sizeof(int))]; -}; - -typedef struct { - uint32_t type; - uint32_t size; -} ProxyHeader; - -#define PROXY_HDR_SZ (sizeof(ProxyHeader)) - -enum { - T_SUCCESS = 0, - T_ERROR, - T_OPEN, - T_CREATE, - T_MKNOD, - T_MKDIR, - T_SYMLINK, - T_LINK, - T_LSTAT, - T_READLINK, - T_STATFS, - T_CHMOD, - T_CHOWN, - T_TRUNCATE, - T_UTIME, - T_RENAME, - T_REMOVE, - T_LGETXATTR, - T_LLISTXATTR, - T_LSETXATTR, - T_LREMOVEXATTR, - T_GETVERSION, -}; - -typedef struct { - uint64_t st_dev; - uint64_t st_ino; - uint64_t st_nlink; - uint32_t st_mode; - uint32_t st_uid; - uint32_t st_gid; - uint64_t st_rdev; - uint64_t st_size; - uint64_t st_blksize; - uint64_t st_blocks; - uint64_t st_atim_sec; - uint64_t st_atim_nsec; - uint64_t st_mtim_sec; - uint64_t st_mtim_nsec; - uint64_t st_ctim_sec; - uint64_t st_ctim_nsec; -} ProxyStat; - -typedef struct { - uint64_t f_type; - uint64_t f_bsize; - uint64_t f_blocks; - uint64_t f_bfree; - uint64_t f_bavail; - uint64_t f_files; - uint64_t f_ffree; - uint64_t f_fsid[2]; - uint64_t f_namelen; - uint64_t f_frsize; -} ProxyStatFS; -#endif diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index f5c953a7105..57877dad0a7 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -89,17 +89,6 @@ static FsDriverTable FsDrivers[] = { NULL }, }, - { - .name = "proxy", - .ops = &proxy_ops, - .opts = (const char * []) { - COMMON_FS_DRIVER_OPTIONS, - "socket", - "sock_fd", - "writeout", - NULL - }, - }, }; static int validate_opt(void *opaque, const char *name, const char *value, @@ -133,14 +122,6 @@ int qemu_fsdev_add(QemuOpts *opts, Error **errp) } if (fsdriver) { - if (strncmp(fsdriver, "proxy", 5) == 0) { - warn_report( - "'-fsdev proxy' and '-virtfs proxy' are deprecated, use " - "'local' instead of 'proxy, or consider deploying virtiofsd " - "as alternative to 9p" - ); - } - for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) { if (strcmp(FsDrivers[i].name, fsdriver) == 0) { break; diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c deleted file mode 100644 index 144aaf585ad..00000000000 --- a/fsdev/virtfs-proxy-helper.c +++ /dev/null @@ -1,1193 +0,0 @@ -/* - * Helper for QEMU Proxy FS Driver - * Copyright IBM, Corp. 2011 - * - * Authors: - * M. Mohan Kumar - * - * This work is licensed under the terms of the GNU GPL, version 2. See - * the COPYING file in the top-level directory. - */ - -/* - * NOTE: The 9p 'proxy' backend is deprecated (since QEMU 8.1) and will be - * removed in a future version of QEMU! - */ - -#include "qemu/osdep.h" -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_LINUX_MAGIC_H -#include -#endif -#include -#include "qemu/sockets.h" -#include "qemu/xattr.h" -#include "9p-iov-marshal.h" -#include "hw/9pfs/9p-proxy.h" -#include "hw/9pfs/9p-util.h" -#include "fsdev/9p-iov-marshal.h" - -#define PROGNAME "virtfs-proxy-helper" - -#ifndef XFS_SUPER_MAGIC -#define XFS_SUPER_MAGIC 0x58465342 -#endif -#ifndef EXT2_SUPER_MAGIC -#define EXT2_SUPER_MAGIC 0xEF53 -#endif -#ifndef REISERFS_SUPER_MAGIC -#define REISERFS_SUPER_MAGIC 0x52654973 -#endif -#ifndef BTRFS_SUPER_MAGIC -#define BTRFS_SUPER_MAGIC 0x9123683E -#endif - -static const struct option helper_opts[] = { - {"fd", required_argument, NULL, 'f'}, - {"path", required_argument, NULL, 'p'}, - {"nodaemon", no_argument, NULL, 'n'}, - {"socket", required_argument, NULL, 's'}, - {"uid", required_argument, NULL, 'u'}, - {"gid", required_argument, NULL, 'g'}, - {}, -}; - -static bool is_daemon; -static bool get_version; /* IOC getversion IOCTL supported */ -static char *prog_name; - -static void G_GNUC_PRINTF(2, 3) do_log(int loglevel, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - if (is_daemon) { - vsyslog(LOG_CRIT, format, ap); - } else { - vfprintf(stderr, format, ap); - } - va_end(ap); -} - -static void do_perror(const char *string) -{ - if (is_daemon) { - syslog(LOG_CRIT, "%s:%s", string, strerror(errno)); - } else { - fprintf(stderr, "%s:%s\n", string, strerror(errno)); - } -} - -static int init_capabilities(void) -{ - /* helper needs following capabilities only */ - int cap_list[] = { - CAP_CHOWN, - CAP_DAC_OVERRIDE, - CAP_FOWNER, - CAP_FSETID, - CAP_SETGID, - CAP_MKNOD, - CAP_SETUID, - }; - int i; - - capng_clear(CAPNG_SELECT_BOTH); - for (i = 0; i < ARRAY_SIZE(cap_list); i++) { - if (capng_update(CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED, - cap_list[i]) < 0) { - do_perror("capng_update"); - return -1; - } - } - if (capng_apply(CAPNG_SELECT_BOTH) < 0) { - do_perror("capng_apply"); - return -1; - } - - /* Prepare effective set for setugid. */ - for (i = 0; i < ARRAY_SIZE(cap_list); i++) { - if (cap_list[i] == CAP_DAC_OVERRIDE) { - continue; - } - - if (capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, - cap_list[i]) < 0) { - do_perror("capng_update"); - return -1; - } - } - return 0; -} - -static int socket_read(int sockfd, void *buff, ssize_t size) -{ - ssize_t retval, total = 0; - - while (size) { - retval = read(sockfd, buff, size); - if (retval == 0) { - return -EIO; - } - if (retval < 0) { - if (errno == EINTR) { - continue; - } - return -errno; - } - size -= retval; - buff += retval; - total += retval; - } - return total; -} - -static int socket_write(int sockfd, void *buff, ssize_t size) -{ - ssize_t retval, total = 0; - - while (size) { - retval = write(sockfd, buff, size); - if (retval < 0) { - if (errno == EINTR) { - continue; - } - return -errno; - } - size -= retval; - buff += retval; - total += retval; - } - return total; -} - -static int read_request(int sockfd, struct iovec *iovec, ProxyHeader *header) -{ - int retval; - - /* - * read the request header. - */ - iovec->iov_len = 0; - retval = socket_read(sockfd, iovec->iov_base, PROXY_HDR_SZ); - if (retval < 0) { - return retval; - } - iovec->iov_len = PROXY_HDR_SZ; - retval = proxy_unmarshal(iovec, 0, "dd", &header->type, &header->size); - if (retval < 0) { - return retval; - } - /* - * We can't process message.size > PROXY_MAX_IO_SZ. - * Treat it as fatal error - */ - if (header->size > PROXY_MAX_IO_SZ) { - return -ENOBUFS; - } - retval = socket_read(sockfd, iovec->iov_base + PROXY_HDR_SZ, header->size); - if (retval < 0) { - return retval; - } - iovec->iov_len += header->size; - return 0; -} - -static int send_fd(int sockfd, int fd) -{ - struct msghdr msg; - struct iovec iov; - int retval, data; - struct cmsghdr *cmsg; - union MsgControl msg_control; - - iov.iov_base = &data; - iov.iov_len = sizeof(data); - - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - /* No ancillary data on error */ - if (fd < 0) { - /* fd is really negative errno if the request failed */ - data = fd; - } else { - data = V9FS_FD_VALID; - msg.msg_control = &msg_control; - msg.msg_controllen = sizeof(msg_control); - - cmsg = &msg_control.cmsg; - cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); - } - - do { - retval = sendmsg(sockfd, &msg, 0); - } while (retval < 0 && errno == EINTR); - if (fd >= 0) { - close(fd); - } - if (retval < 0) { - return retval; - } - return 0; -} - -static int send_status(int sockfd, struct iovec *iovec, int status) -{ - ProxyHeader header; - int retval, msg_size; - - if (status < 0) { - header.type = T_ERROR; - } else { - header.type = T_SUCCESS; - } - header.size = sizeof(status); - /* - * marshal the return status. We don't check error. - * because we are sure we have enough space for the status - */ - msg_size = proxy_marshal(iovec, 0, "ddd", header.type, - header.size, status); - if (msg_size < 0) { - return msg_size; - } - retval = socket_write(sockfd, iovec->iov_base, msg_size); - if (retval < 0) { - return retval; - } - return 0; -} - -/* - * from man 7 capabilities, section - * Effect of User ID Changes on Capabilities: - * If the effective user ID is changed from nonzero to 0, then the permitted - * set is copied to the effective set. If the effective user ID is changed - * from 0 to nonzero, then all capabilities are are cleared from the effective - * set. - * - * The setfsuid/setfsgid man pages warn that changing the effective user ID may - * expose the program to unwanted signals, but this is not true anymore: for an - * unprivileged (without CAP_KILL) program to send a signal, the real or - * effective user ID of the sending process must equal the real or saved user - * ID of the target process. Even when dropping privileges, it is enough to - * keep the saved UID to a "privileged" value and virtfs-proxy-helper won't - * be exposed to signals. So just use setresuid/setresgid. - */ -static int setugid(int uid, int gid, int *suid, int *sgid) -{ - int retval; - - *suid = geteuid(); - *sgid = getegid(); - - if (setresgid(-1, gid, *sgid) == -1) { - return -errno; - } - - if (setresuid(-1, uid, *suid) == -1) { - retval = -errno; - goto err_sgid; - } - - if (uid == 0 && gid == 0) { - /* Linux has already copied the permitted set to the effective set. */ - return 0; - } - - /* - * All capabilities have been cleared from the effective set. However - * we still need DAC_OVERRIDE because we don't change supplementary - * group ids, and hence may be subject to DAC rules. init_capabilities - * left the set of capabilities that we want in libcap-ng's state. - */ - if (capng_apply(CAPNG_SELECT_CAPS) < 0) { - retval = -errno; - do_perror("capng_apply"); - goto err_suid; - } - return 0; - -err_suid: - if (setresuid(-1, *suid, *suid) == -1) { - abort(); - } -err_sgid: - if (setresgid(-1, *sgid, *sgid) == -1) { - abort(); - } - return retval; -} - -/* - * This is used to reset the ugid back with the saved values - * There is nothing much we can do checking error values here. - */ -static void resetugid(int suid, int sgid) -{ - if (setresgid(-1, sgid, sgid) == -1) { - abort(); - } - if (setresuid(-1, suid, suid) == -1) { - abort(); - } -} - -/* - * Open regular file or directory. Attempts to open any special file are - * rejected. - * - * returns file descriptor or -1 on error - */ -static int open_regular(const char *pathname, int flags, mode_t mode) -{ - int fd; - - fd = open(pathname, flags, mode); - if (fd < 0) { - return fd; - } - - if (close_if_special_file(fd) < 0) { - return -1; - } - - return fd; -} - -/* - * send response in two parts - * 1) ProxyHeader - * 2) Response or error status - * This function should be called with marshaled response - * send_response constructs header part and error part only. - * send response sends {ProxyHeader,Response} if the request was success - * otherwise sends {ProxyHeader,error status} - */ -static int send_response(int sock, struct iovec *iovec, int size) -{ - int retval; - ProxyHeader header; - - /* - * If response size exceeds available iovec->iov_len, - * we return ENOBUFS - */ - if (size > PROXY_MAX_IO_SZ) { - size = -ENOBUFS; - } - - if (size < 0) { - /* - * In case of error we would not have got the error encoded - * already so encode the error here. - */ - header.type = T_ERROR; - header.size = sizeof(size); - proxy_marshal(iovec, PROXY_HDR_SZ, "d", size); - } else { - header.type = T_SUCCESS; - header.size = size; - } - proxy_marshal(iovec, 0, "dd", header.type, header.size); - retval = socket_write(sock, iovec->iov_base, header.size + PROXY_HDR_SZ); - if (retval < 0) { - return retval; - } - return 0; -} - -/* - * gets generation number - * returns -errno on failure and sizeof(generation number) on success - */ -static int do_getversion(struct iovec *iovec, struct iovec *out_iovec) -{ - uint64_t version; - int retval = -ENOTTY; -#ifdef FS_IOC_GETVERSION - int fd; - V9fsString path; -#endif - - - /* no need to issue ioctl */ - if (!get_version) { - version = 0; - retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, "q", version); - return retval; - } -#ifdef FS_IOC_GETVERSION - retval = proxy_unmarshal(iovec, PROXY_HDR_SZ, "s", &path); - if (retval < 0) { - return retval; - } - - fd = open(path.data, O_RDONLY); - if (fd < 0) { - retval = -errno; - goto err_out; - } - if (ioctl(fd, FS_IOC_GETVERSION, &version) < 0) { - retval = -errno; - } else { - retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, "q", version); - } - close(fd); -err_out: - v9fs_string_free(&path); -#endif - return retval; -} - -static int do_getxattr(int type, struct iovec *iovec, struct iovec *out_iovec) -{ - int size = 0, offset, retval; - V9fsString path, name, xattr; - - v9fs_string_init(&xattr); - v9fs_string_init(&path); - retval = proxy_unmarshal(iovec, PROXY_HDR_SZ, "ds", &size, &path); - if (retval < 0) { - return retval; - } - offset = PROXY_HDR_SZ + retval; - - if (size) { - xattr.data = g_malloc(size); - xattr.size = size; - } - switch (type) { - case T_LGETXATTR: - v9fs_string_init(&name); - retval = proxy_unmarshal(iovec, offset, "s", &name); - if (retval > 0) { - retval = lgetxattr(path.data, name.data, xattr.data, size); - if (retval < 0) { - retval = -errno; - } else { - xattr.size = retval; - } - } - v9fs_string_free(&name); - break; - case T_LLISTXATTR: - retval = llistxattr(path.data, xattr.data, size); - if (retval < 0) { - retval = -errno; - } else { - xattr.size = retval; - } - break; - } - if (retval < 0) { - goto err_out; - } - - if (!size) { - proxy_marshal(out_iovec, PROXY_HDR_SZ, "d", retval); - retval = sizeof(retval); - } else { - retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, "s", &xattr); - } -err_out: - v9fs_string_free(&xattr); - v9fs_string_free(&path); - return retval; -} - -static void stat_to_prstat(ProxyStat *pr_stat, struct stat *stat) -{ - memset(pr_stat, 0, sizeof(*pr_stat)); - pr_stat->st_dev = stat->st_dev; - pr_stat->st_ino = stat->st_ino; - pr_stat->st_nlink = stat->st_nlink; - pr_stat->st_mode = stat->st_mode; - pr_stat->st_uid = stat->st_uid; - pr_stat->st_gid = stat->st_gid; - pr_stat->st_rdev = stat->st_rdev; - pr_stat->st_size = stat->st_size; - pr_stat->st_blksize = stat->st_blksize; - pr_stat->st_blocks = stat->st_blocks; - pr_stat->st_atim_sec = stat->st_atim.tv_sec; - pr_stat->st_atim_nsec = stat->st_atim.tv_nsec; - pr_stat->st_mtim_sec = stat->st_mtim.tv_sec; - pr_stat->st_mtim_nsec = stat->st_mtim.tv_nsec; - pr_stat->st_ctim_sec = stat->st_ctim.tv_sec; - pr_stat->st_ctim_nsec = stat->st_ctim.tv_nsec; -} - -static void statfs_to_prstatfs(ProxyStatFS *pr_stfs, struct statfs *stfs) -{ - memset(pr_stfs, 0, sizeof(*pr_stfs)); - pr_stfs->f_type = stfs->f_type; - pr_stfs->f_bsize = stfs->f_bsize; - pr_stfs->f_blocks = stfs->f_blocks; - pr_stfs->f_bfree = stfs->f_bfree; - pr_stfs->f_bavail = stfs->f_bavail; - pr_stfs->f_files = stfs->f_files; - pr_stfs->f_ffree = stfs->f_ffree; - pr_stfs->f_fsid[0] = stfs->f_fsid.__val[0]; - pr_stfs->f_fsid[1] = stfs->f_fsid.__val[1]; - pr_stfs->f_namelen = stfs->f_namelen; - pr_stfs->f_frsize = stfs->f_frsize; -} - -/* - * Gets stat/statfs information and packs in out_iovec structure - * on success returns number of bytes packed in out_iovec structure - * otherwise returns -errno - */ -static int do_stat(int type, struct iovec *iovec, struct iovec *out_iovec) -{ - int retval; - V9fsString path; - ProxyStat pr_stat; - ProxyStatFS pr_stfs; - struct stat st_buf; - struct statfs stfs_buf; - - v9fs_string_init(&path); - retval = proxy_unmarshal(iovec, PROXY_HDR_SZ, "s", &path); - if (retval < 0) { - return retval; - } - - switch (type) { - case T_LSTAT: - retval = lstat(path.data, &st_buf); - if (retval < 0) { - retval = -errno; - } else { - stat_to_prstat(&pr_stat, &st_buf); - retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, - "qqqdddqqqqqqqqqq", pr_stat.st_dev, - pr_stat.st_ino, pr_stat.st_nlink, - pr_stat.st_mode, pr_stat.st_uid, - pr_stat.st_gid, pr_stat.st_rdev, - pr_stat.st_size, pr_stat.st_blksize, - pr_stat.st_blocks, - pr_stat.st_atim_sec, pr_stat.st_atim_nsec, - pr_stat.st_mtim_sec, pr_stat.st_mtim_nsec, - pr_stat.st_ctim_sec, pr_stat.st_ctim_nsec); - } - break; - case T_STATFS: - retval = statfs(path.data, &stfs_buf); - if (retval < 0) { - retval = -errno; - } else { - statfs_to_prstatfs(&pr_stfs, &stfs_buf); - retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, - "qqqqqqqqqqq", pr_stfs.f_type, - pr_stfs.f_bsize, pr_stfs.f_blocks, - pr_stfs.f_bfree, pr_stfs.f_bavail, - pr_stfs.f_files, pr_stfs.f_ffree, - pr_stfs.f_fsid[0], pr_stfs.f_fsid[1], - pr_stfs.f_namelen, pr_stfs.f_frsize); - } - break; - } - v9fs_string_free(&path); - return retval; -} - -static int do_readlink(struct iovec *iovec, struct iovec *out_iovec) -{ - char *buffer; - int size, retval; - V9fsString target, path; - - v9fs_string_init(&path); - retval = proxy_unmarshal(iovec, PROXY_HDR_SZ, "sd", &path, &size); - if (retval < 0) { - v9fs_string_free(&path); - return retval; - } - buffer = g_malloc(size); - v9fs_string_init(&target); - retval = readlink(path.data, buffer, size - 1); - if (retval > 0) { - buffer[retval] = '\0'; - v9fs_string_sprintf(&target, "%s", buffer); - retval = proxy_marshal(out_iovec, PROXY_HDR_SZ, "s", &target); - } else { - retval = -errno; - } - g_free(buffer); - v9fs_string_free(&target); - v9fs_string_free(&path); - return retval; -} - -/* - * create other filesystem objects and send 0 on success - * return -errno on error - */ -static int do_create_others(int type, struct iovec *iovec) -{ - dev_t rdev; - int retval = 0; - int offset = PROXY_HDR_SZ; - V9fsString oldpath, path; - int mode, uid, gid, cur_uid, cur_gid; - - v9fs_string_init(&path); - v9fs_string_init(&oldpath); - - retval = proxy_unmarshal(iovec, offset, "dd", &uid, &gid); - if (retval < 0) { - return retval; - } - offset += retval; - retval = setugid(uid, gid, &cur_uid, &cur_gid); - if (retval < 0) { - goto unmarshal_err_out; - } - switch (type) { - case T_MKNOD: - retval = proxy_unmarshal(iovec, offset, "sdq", &path, &mode, &rdev); - if (retval < 0) { - goto err_out; - } - retval = mknod(path.data, mode, rdev); - break; - case T_MKDIR: - retval = proxy_unmarshal(iovec, offset, "sd", &path, &mode); - if (retval < 0) { - goto err_out; - } - retval = g_mkdir(path.data, mode); - break; - case T_SYMLINK: - retval = proxy_unmarshal(iovec, offset, "ss", &oldpath, &path); - if (retval < 0) { - goto err_out; - } - retval = symlink(oldpath.data, path.data); - break; - } - if (retval < 0) { - retval = -errno; - } - -err_out: - resetugid(cur_uid, cur_gid); -unmarshal_err_out: - v9fs_string_free(&path); - v9fs_string_free(&oldpath); - return retval; -} - -/* - * create a file and send fd on success - * return -errno on error - */ -static int do_create(struct iovec *iovec) -{ - int ret; - V9fsString path; - int flags, mode, uid, gid, cur_uid, cur_gid; - - v9fs_string_init(&path); - ret = proxy_unmarshal(iovec, PROXY_HDR_SZ, "sdddd", - &path, &flags, &mode, &uid, &gid); - if (ret < 0) { - goto unmarshal_err_out; - } - ret = setugid(uid, gid, &cur_uid, &cur_gid); - if (ret < 0) { - goto unmarshal_err_out; - } - ret = open_regular(path.data, flags, mode); - if (ret < 0) { - ret = -errno; - } - - resetugid(cur_uid, cur_gid); -unmarshal_err_out: - v9fs_string_free(&path); - return ret; -} - -/* - * open a file and send fd on success - * return -errno on error - */ -static int do_open(struct iovec *iovec) -{ - int flags, ret; - V9fsString path; - - v9fs_string_init(&path); - ret = proxy_unmarshal(iovec, PROXY_HDR_SZ, "sd", &path, &flags); - if (ret < 0) { - goto err_out; - } - ret = open_regular(path.data, flags, 0); - if (ret < 0) { - ret = -errno; - } -err_out: - v9fs_string_free(&path); - return ret; -} - -/* create unix domain socket and return the descriptor */ -static int proxy_socket(const char *path, uid_t uid, gid_t gid) -{ - int sock, client; - struct sockaddr_un proxy, qemu; - socklen_t size; - - /* requested socket already exists, refuse to start */ - if (!access(path, F_OK)) { - do_log(LOG_CRIT, "socket already exists\n"); - return -1; - } - - if (strlen(path) >= sizeof(proxy.sun_path)) { - do_log(LOG_CRIT, "UNIX domain socket path exceeds %zu characters\n", - sizeof(proxy.sun_path)); - return -1; - } - - sock = socket(AF_UNIX, SOCK_STREAM, 0); - if (sock < 0) { - do_perror("socket"); - return -1; - } - - /* mask other part of mode bits */ - umask(7); - - proxy.sun_family = AF_UNIX; - strcpy(proxy.sun_path, path); - if (bind(sock, (struct sockaddr *)&proxy, - sizeof(struct sockaddr_un)) < 0) { - do_perror("bind"); - goto error; - } - if (chown(proxy.sun_path, uid, gid) < 0) { - do_perror("chown"); - goto error; - } - if (listen(sock, 1) < 0) { - do_perror("listen"); - goto error; - } - - size = sizeof(qemu); - client = accept(sock, (struct sockaddr *)&qemu, &size); - if (client < 0) { - do_perror("accept"); - goto error; - } - close(sock); - return client; - -error: - close(sock); - return -1; -} - -static void usage(void) -{ - fprintf(stderr, "usage: %s\n" - " -p|--path 9p path to export\n" - " {-f|--fd } socket file descriptor to be used\n" - " {-s|--socket socket file used for communication\n" - " \t-u|--uid -g|--gid } - uid:gid combination to give " - " access to this socket\n" - " \tNote: -s & -f can not be used together\n" - " [-n|--nodaemon] Run as a normal program\n", - prog_name); -} - -static int process_reply(int sock, int type, - struct iovec *out_iovec, int retval) -{ - switch (type) { - case T_OPEN: - case T_CREATE: - if (send_fd(sock, retval) < 0) { - return -1; - } - break; - case T_MKNOD: - case T_MKDIR: - case T_SYMLINK: - case T_LINK: - case T_CHMOD: - case T_CHOWN: - case T_TRUNCATE: - case T_UTIME: - case T_RENAME: - case T_REMOVE: - case T_LSETXATTR: - case T_LREMOVEXATTR: - if (send_status(sock, out_iovec, retval) < 0) { - return -1; - } - break; - case T_LSTAT: - case T_STATFS: - case T_READLINK: - case T_LGETXATTR: - case T_LLISTXATTR: - case T_GETVERSION: - if (send_response(sock, out_iovec, retval) < 0) { - return -1; - } - break; - default: - return -1; - break; - } - return 0; -} - -static int process_requests(int sock) -{ - int flags; - int size = 0; - int retval = 0; - uint64_t offset; - ProxyHeader header; - int mode, uid, gid; - V9fsString name, value; - struct timespec spec[2]; - V9fsString oldpath, path; - struct iovec in_iovec, out_iovec; - - in_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); - in_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; - out_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); - out_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; - - while (1) { - /* - * initialize the header type, so that we send - * response to proper request type. - */ - header.type = 0; - retval = read_request(sock, &in_iovec, &header); - if (retval < 0) { - goto err_out; - } - - switch (header.type) { - case T_OPEN: - retval = do_open(&in_iovec); - break; - case T_CREATE: - retval = do_create(&in_iovec); - break; - case T_MKNOD: - case T_MKDIR: - case T_SYMLINK: - retval = do_create_others(header.type, &in_iovec); - break; - case T_LINK: - v9fs_string_init(&path); - v9fs_string_init(&oldpath); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, - "ss", &oldpath, &path); - if (retval > 0) { - retval = link(oldpath.data, path.data); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&oldpath); - v9fs_string_free(&path); - break; - case T_LSTAT: - case T_STATFS: - retval = do_stat(header.type, &in_iovec, &out_iovec); - break; - case T_READLINK: - retval = do_readlink(&in_iovec, &out_iovec); - break; - case T_CHMOD: - v9fs_string_init(&path); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, - "sd", &path, &mode); - if (retval > 0) { - retval = chmod(path.data, mode); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&path); - break; - case T_CHOWN: - v9fs_string_init(&path); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sdd", &path, - &uid, &gid); - if (retval > 0) { - retval = lchown(path.data, uid, gid); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&path); - break; - case T_TRUNCATE: - v9fs_string_init(&path); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sq", - &path, &offset); - if (retval > 0) { - retval = truncate(path.data, offset); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&path); - break; - case T_UTIME: - v9fs_string_init(&path); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sqqqq", &path, - &spec[0].tv_sec, &spec[0].tv_nsec, - &spec[1].tv_sec, &spec[1].tv_nsec); - if (retval > 0) { - retval = utimensat(AT_FDCWD, path.data, spec, - AT_SYMLINK_NOFOLLOW); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&path); - break; - case T_RENAME: - v9fs_string_init(&path); - v9fs_string_init(&oldpath); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, - "ss", &oldpath, &path); - if (retval > 0) { - retval = rename(oldpath.data, path.data); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&oldpath); - v9fs_string_free(&path); - break; - case T_REMOVE: - v9fs_string_init(&path); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "s", &path); - if (retval > 0) { - retval = remove(path.data); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&path); - break; - case T_LGETXATTR: - case T_LLISTXATTR: - retval = do_getxattr(header.type, &in_iovec, &out_iovec); - break; - case T_LSETXATTR: - v9fs_string_init(&path); - v9fs_string_init(&name); - v9fs_string_init(&value); - retval = proxy_unmarshal(&in_iovec, PROXY_HDR_SZ, "sssdd", &path, - &name, &value, &size, &flags); - if (retval > 0) { - retval = lsetxattr(path.data, - name.data, value.data, size, flags); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&path); - v9fs_string_free(&name); - v9fs_string_free(&value); - break; - case T_LREMOVEXATTR: - v9fs_string_init(&path); - v9fs_string_init(&name); - retval = proxy_unmarshal(&in_iovec, - PROXY_HDR_SZ, "ss", &path, &name); - if (retval > 0) { - retval = lremovexattr(path.data, name.data); - if (retval < 0) { - retval = -errno; - } - } - v9fs_string_free(&path); - v9fs_string_free(&name); - break; - case T_GETVERSION: - retval = do_getversion(&in_iovec, &out_iovec); - break; - default: - goto err_out; - break; - } - - if (process_reply(sock, header.type, &out_iovec, retval) < 0) { - goto err_out; - } - } -err_out: - g_free(in_iovec.iov_base); - g_free(out_iovec.iov_base); - return -1; -} - -int main(int argc, char **argv) -{ - int sock; - uid_t own_u; - gid_t own_g; - char *rpath = NULL; - char *sock_name = NULL; - struct stat stbuf; - int c, option_index; -#ifdef FS_IOC_GETVERSION - int retval; - struct statfs st_fs; -#endif - - fprintf(stderr, "NOTE: The 9p 'proxy' backend is deprecated (since " - "QEMU 8.1) and will be removed in a future version of " - "QEMU!\n"); - - prog_name = g_path_get_basename(argv[0]); - - is_daemon = true; - sock = -1; - own_u = own_g = -1; - while (1) { - option_index = 0; - c = getopt_long(argc, argv, "p:nh?f:s:u:g:", helper_opts, - &option_index); - if (c == -1) { - break; - } - switch (c) { - case 'p': - rpath = g_strdup(optarg); - break; - case 'n': - is_daemon = false; - break; - case 'f': - sock = atoi(optarg); - break; - case 's': - sock_name = g_strdup(optarg); - break; - case 'u': - own_u = atoi(optarg); - break; - case 'g': - own_g = atoi(optarg); - break; - case '?': - case 'h': - default: - usage(); - exit(EXIT_FAILURE); - } - } - - /* Parameter validation */ - if ((sock_name == NULL && sock == -1) || rpath == NULL) { - fprintf(stderr, "socket, socket descriptor or path not specified\n"); - usage(); - return -1; - } - - if (sock_name && sock != -1) { - fprintf(stderr, "both named socket and socket descriptor specified\n"); - usage(); - exit(EXIT_FAILURE); - } - - if (sock_name && (own_u == -1 || own_g == -1)) { - fprintf(stderr, "owner uid:gid not specified, "); - fprintf(stderr, - "owner uid:gid specifies who can access the socket file\n"); - usage(); - exit(EXIT_FAILURE); - } - - if (lstat(rpath, &stbuf) < 0) { - fprintf(stderr, "invalid path \"%s\" specified, %s\n", - rpath, strerror(errno)); - exit(EXIT_FAILURE); - } - - if (!S_ISDIR(stbuf.st_mode)) { - fprintf(stderr, "specified path \"%s\" is not directory\n", rpath); - exit(EXIT_FAILURE); - } - - if (is_daemon) { - if (daemon(0, 0) < 0) { - fprintf(stderr, "daemon call failed\n"); - exit(EXIT_FAILURE); - } - openlog(PROGNAME, LOG_PID, LOG_DAEMON); - } - - do_log(LOG_INFO, "Started\n"); - if (sock_name) { - sock = proxy_socket(sock_name, own_u, own_g); - if (sock < 0) { - goto error; - } - } - - if (chroot(rpath) < 0) { - do_perror("chroot"); - goto error; - } - if (chdir("/") < 0) { - do_perror("chdir"); - goto error; - } - - get_version = false; -#ifdef FS_IOC_GETVERSION - /* check whether underlying FS support IOC_GETVERSION */ - retval = statfs("/", &st_fs); - if (!retval) { - switch (st_fs.f_type) { - case EXT2_SUPER_MAGIC: - case BTRFS_SUPER_MAGIC: - case REISERFS_SUPER_MAGIC: - case XFS_SUPER_MAGIC: - get_version = true; - break; - } - } -#endif - - umask(0); - if (init_capabilities() < 0) { - goto error; - } - - process_requests(sock); -error: - g_free(rpath); - g_free(sock_name); - do_log(LOG_INFO, "Done\n"); - closelog(); - return 0; -} diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c deleted file mode 100644 index 7aac49ad4ad..00000000000 --- a/hw/9pfs/9p-proxy.c +++ /dev/null @@ -1,1279 +0,0 @@ -/* - * 9p Proxy callback - * - * Copyright IBM, Corp. 2011 - * - * Authors: - * M. Mohan Kumar - * - * This work is licensed under the terms of the GNU GPL, version 2. See - * the COPYING file in the top-level directory. - */ - -/* - * Not so fast! You might want to read the 9p developer docs first: - * https://wiki.qemu.org/Documentation/9p - */ - -/* - * NOTE: The 9p 'proxy' backend is deprecated (since QEMU 8.1) and will be - * removed in a future version of QEMU! - */ - -#include "qemu/osdep.h" -#include -#include -#include "9p.h" -#include "qapi/error.h" -#include "qemu/cutils.h" -#include "qemu/error-report.h" -#include "qemu/option.h" -#include "fsdev/qemu-fsdev.h" -#include "9p-proxy.h" - -typedef struct V9fsProxy { - int sockfd; - QemuMutex mutex; - struct iovec in_iovec; - struct iovec out_iovec; -} V9fsProxy; - -/* - * Return received file descriptor on success in *status. - * errno is also returned on *status (which will be < 0) - * return < 0 on transport error. - */ -static int v9fs_receivefd(int sockfd, int *status) -{ - struct iovec iov; - struct msghdr msg; - struct cmsghdr *cmsg; - int retval, data, fd; - union MsgControl msg_control; - - iov.iov_base = &data; - iov.iov_len = sizeof(data); - - memset(&msg, 0, sizeof(msg)); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = &msg_control; - msg.msg_controllen = sizeof(msg_control); - - do { - retval = recvmsg(sockfd, &msg, 0); - } while (retval < 0 && errno == EINTR); - if (retval <= 0) { - return retval; - } - /* - * data is set to V9FS_FD_VALID, if ancillary data is sent. If this - * request doesn't need ancillary data (fd) or an error occurred, - * data is set to negative errno value. - */ - if (data != V9FS_FD_VALID) { - *status = data; - return 0; - } - /* - * File descriptor (fd) is sent in the ancillary data. Check if we - * indeed received it. One of the reasons to fail to receive it is if - * we exceeded the maximum number of file descriptors! - */ - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)) || - cmsg->cmsg_level != SOL_SOCKET || - cmsg->cmsg_type != SCM_RIGHTS) { - continue; - } - fd = *((int *)CMSG_DATA(cmsg)); - *status = fd; - return 0; - } - *status = -ENFILE; /* Ancillary data sent but not received */ - return 0; -} - -static ssize_t socket_read(int sockfd, void *buff, size_t size) -{ - ssize_t retval, total = 0; - - while (size) { - retval = read(sockfd, buff, size); - if (retval == 0) { - return -EIO; - } - if (retval < 0) { - if (errno == EINTR) { - continue; - } - return -errno; - } - size -= retval; - buff += retval; - total += retval; - } - return total; -} - -/* Converts proxy_statfs to VFS statfs structure */ -static void prstatfs_to_statfs(struct statfs *stfs, ProxyStatFS *prstfs) -{ - memset(stfs, 0, sizeof(*stfs)); - stfs->f_type = prstfs->f_type; - stfs->f_bsize = prstfs->f_bsize; - stfs->f_blocks = prstfs->f_blocks; - stfs->f_bfree = prstfs->f_bfree; - stfs->f_bavail = prstfs->f_bavail; - stfs->f_files = prstfs->f_files; - stfs->f_ffree = prstfs->f_ffree; -#ifdef CONFIG_DARWIN - /* f_namelen and f_frsize do not exist on Darwin */ - stfs->f_fsid.val[0] = prstfs->f_fsid[0] & 0xFFFFFFFFU; - stfs->f_fsid.val[1] = prstfs->f_fsid[1] >> 32 & 0xFFFFFFFFU; -#else - stfs->f_fsid.__val[0] = prstfs->f_fsid[0] & 0xFFFFFFFFU; - stfs->f_fsid.__val[1] = prstfs->f_fsid[1] >> 32 & 0xFFFFFFFFU; - stfs->f_namelen = prstfs->f_namelen; - stfs->f_frsize = prstfs->f_frsize; -#endif -} - -/* Converts proxy_stat structure to VFS stat structure */ -static void prstat_to_stat(struct stat *stbuf, ProxyStat *prstat) -{ - memset(stbuf, 0, sizeof(*stbuf)); - stbuf->st_dev = prstat->st_dev; - stbuf->st_ino = prstat->st_ino; - stbuf->st_nlink = prstat->st_nlink; - stbuf->st_mode = prstat->st_mode; - stbuf->st_uid = prstat->st_uid; - stbuf->st_gid = prstat->st_gid; - stbuf->st_rdev = prstat->st_rdev; - stbuf->st_size = prstat->st_size; - stbuf->st_blksize = prstat->st_blksize; - stbuf->st_blocks = prstat->st_blocks; - stbuf->st_atime = prstat->st_atim_sec; - stbuf->st_mtime = prstat->st_mtim_sec; - stbuf->st_ctime = prstat->st_ctim_sec; -#ifdef CONFIG_DARWIN - stbuf->st_atimespec.tv_sec = prstat->st_atim_sec; - stbuf->st_mtimespec.tv_sec = prstat->st_mtim_sec; - stbuf->st_ctimespec.tv_sec = prstat->st_ctim_sec; - stbuf->st_atimespec.tv_nsec = prstat->st_atim_nsec; - stbuf->st_mtimespec.tv_nsec = prstat->st_mtim_nsec; - stbuf->st_ctimespec.tv_nsec = prstat->st_ctim_nsec; -#else - stbuf->st_atim.tv_sec = prstat->st_atim_sec; - stbuf->st_mtim.tv_sec = prstat->st_mtim_sec; - stbuf->st_ctim.tv_sec = prstat->st_ctim_sec; - stbuf->st_atim.tv_nsec = prstat->st_atim_nsec; - stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec; - stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec; -#endif -} - -/* - * Response contains two parts - * {header, data} - * header.type == T_ERROR, data -> -errno - * header.type == T_SUCCESS, data -> response - * size of errno/response is given by header.size - * returns < 0, on transport error. response is - * valid only if status >= 0. - */ -static int v9fs_receive_response(V9fsProxy *proxy, int type, - int *status, void *response) -{ - int retval; - ProxyHeader header; - struct iovec *reply = &proxy->in_iovec; - - *status = 0; - reply->iov_len = 0; - retval = socket_read(proxy->sockfd, reply->iov_base, PROXY_HDR_SZ); - if (retval < 0) { - return retval; - } - reply->iov_len = PROXY_HDR_SZ; - retval = proxy_unmarshal(reply, 0, "dd", &header.type, &header.size); - assert(retval == 4 * 2); - /* - * if response size > PROXY_MAX_IO_SZ, read the response but ignore it and - * return -ENOBUFS - */ - if (header.size > PROXY_MAX_IO_SZ) { - int count; - while (header.size > 0) { - count = MIN(PROXY_MAX_IO_SZ, header.size); - count = socket_read(proxy->sockfd, reply->iov_base, count); - if (count < 0) { - return count; - } - header.size -= count; - } - *status = -ENOBUFS; - return 0; - } - - retval = socket_read(proxy->sockfd, - reply->iov_base + PROXY_HDR_SZ, header.size); - if (retval < 0) { - return retval; - } - reply->iov_len += header.size; - /* there was an error during processing request */ - if (header.type == T_ERROR) { - int ret; - ret = proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status); - assert(ret == 4); - return 0; - } - - switch (type) { - case T_LSTAT: { - ProxyStat prstat; - retval = proxy_unmarshal(reply, PROXY_HDR_SZ, - "qqqdddqqqqqqqqqq", &prstat.st_dev, - &prstat.st_ino, &prstat.st_nlink, - &prstat.st_mode, &prstat.st_uid, - &prstat.st_gid, &prstat.st_rdev, - &prstat.st_size, &prstat.st_blksize, - &prstat.st_blocks, - &prstat.st_atim_sec, &prstat.st_atim_nsec, - &prstat.st_mtim_sec, &prstat.st_mtim_nsec, - &prstat.st_ctim_sec, &prstat.st_ctim_nsec); - assert(retval == 8 * 3 + 4 * 3 + 8 * 10); - prstat_to_stat(response, &prstat); - break; - } - case T_STATFS: { - ProxyStatFS prstfs; - retval = proxy_unmarshal(reply, PROXY_HDR_SZ, - "qqqqqqqqqqq", &prstfs.f_type, - &prstfs.f_bsize, &prstfs.f_blocks, - &prstfs.f_bfree, &prstfs.f_bavail, - &prstfs.f_files, &prstfs.f_ffree, - &prstfs.f_fsid[0], &prstfs.f_fsid[1], - &prstfs.f_namelen, &prstfs.f_frsize); - assert(retval == 8 * 11); - prstatfs_to_statfs(response, &prstfs); - break; - } - case T_READLINK: { - V9fsString target; - v9fs_string_init(&target); - retval = proxy_unmarshal(reply, PROXY_HDR_SZ, "s", &target); - strcpy(response, target.data); - v9fs_string_free(&target); - break; - } - case T_LGETXATTR: - case T_LLISTXATTR: { - V9fsString xattr; - v9fs_string_init(&xattr); - retval = proxy_unmarshal(reply, PROXY_HDR_SZ, "s", &xattr); - memcpy(response, xattr.data, xattr.size); - v9fs_string_free(&xattr); - break; - } - case T_GETVERSION: - retval = proxy_unmarshal(reply, PROXY_HDR_SZ, "q", response); - assert(retval == 8); - break; - default: - return -1; - } - if (retval < 0) { - *status = retval; - } - return 0; -} - -/* - * return < 0 on transport error. - * *status is valid only if return >= 0 - */ -static int v9fs_receive_status(V9fsProxy *proxy, - struct iovec *reply, int *status) -{ - int retval; - ProxyHeader header; - - *status = 0; - reply->iov_len = 0; - retval = socket_read(proxy->sockfd, reply->iov_base, PROXY_HDR_SZ); - if (retval < 0) { - return retval; - } - reply->iov_len = PROXY_HDR_SZ; - retval = proxy_unmarshal(reply, 0, "dd", &header.type, &header.size); - assert(retval == 4 * 2); - retval = socket_read(proxy->sockfd, - reply->iov_base + PROXY_HDR_SZ, header.size); - if (retval < 0) { - return retval; - } - reply->iov_len += header.size; - retval = proxy_unmarshal(reply, PROXY_HDR_SZ, "d", status); - assert(retval == 4); - return 0; -} - -/* - * Proxy->header and proxy->request written to socket by QEMU process. - * This request read by proxy helper process - * returns 0 on success and -errno on error - */ -static int v9fs_request(V9fsProxy *proxy, int type, void *response, ...) -{ - dev_t rdev; - va_list ap; - int size = 0; - int retval = 0; - uint64_t offset; - ProxyHeader header = { 0, 0}; - struct timespec spec[2]; - int flags, mode, uid, gid; - V9fsString *name, *value; - V9fsString *path, *oldpath; - struct iovec *iovec = NULL, *reply = NULL; - - qemu_mutex_lock(&proxy->mutex); - - if (proxy->sockfd == -1) { - retval = -EIO; - goto err_out; - } - iovec = &proxy->out_iovec; - reply = &proxy->in_iovec; - va_start(ap, response); - switch (type) { - case T_OPEN: - path = va_arg(ap, V9fsString *); - flags = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sd", path, flags); - if (retval > 0) { - header.size = retval; - header.type = T_OPEN; - } - break; - case T_CREATE: - path = va_arg(ap, V9fsString *); - flags = va_arg(ap, int); - mode = va_arg(ap, int); - uid = va_arg(ap, int); - gid = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sdddd", path, - flags, mode, uid, gid); - if (retval > 0) { - header.size = retval; - header.type = T_CREATE; - } - break; - case T_MKNOD: - path = va_arg(ap, V9fsString *); - mode = va_arg(ap, int); - rdev = va_arg(ap, long int); - uid = va_arg(ap, int); - gid = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ddsdq", - uid, gid, path, mode, rdev); - if (retval > 0) { - header.size = retval; - header.type = T_MKNOD; - } - break; - case T_MKDIR: - path = va_arg(ap, V9fsString *); - mode = va_arg(ap, int); - uid = va_arg(ap, int); - gid = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ddsd", - uid, gid, path, mode); - if (retval > 0) { - header.size = retval; - header.type = T_MKDIR; - } - break; - case T_SYMLINK: - oldpath = va_arg(ap, V9fsString *); - path = va_arg(ap, V9fsString *); - uid = va_arg(ap, int); - gid = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ddss", - uid, gid, oldpath, path); - if (retval > 0) { - header.size = retval; - header.type = T_SYMLINK; - } - break; - case T_LINK: - oldpath = va_arg(ap, V9fsString *); - path = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ss", - oldpath, path); - if (retval > 0) { - header.size = retval; - header.type = T_LINK; - } - break; - case T_LSTAT: - path = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); - if (retval > 0) { - header.size = retval; - header.type = T_LSTAT; - } - break; - case T_READLINK: - path = va_arg(ap, V9fsString *); - size = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sd", path, size); - if (retval > 0) { - header.size = retval; - header.type = T_READLINK; - } - break; - case T_STATFS: - path = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); - if (retval > 0) { - header.size = retval; - header.type = T_STATFS; - } - break; - case T_CHMOD: - path = va_arg(ap, V9fsString *); - mode = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sd", path, mode); - if (retval > 0) { - header.size = retval; - header.type = T_CHMOD; - } - break; - case T_CHOWN: - path = va_arg(ap, V9fsString *); - uid = va_arg(ap, int); - gid = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sdd", path, uid, gid); - if (retval > 0) { - header.size = retval; - header.type = T_CHOWN; - } - break; - case T_TRUNCATE: - path = va_arg(ap, V9fsString *); - offset = va_arg(ap, uint64_t); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sq", path, offset); - if (retval > 0) { - header.size = retval; - header.type = T_TRUNCATE; - } - break; - case T_UTIME: - path = va_arg(ap, V9fsString *); - spec[0].tv_sec = va_arg(ap, long); - spec[0].tv_nsec = va_arg(ap, long); - spec[1].tv_sec = va_arg(ap, long); - spec[1].tv_nsec = va_arg(ap, long); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sqqqq", path, - spec[0].tv_sec, spec[1].tv_nsec, - spec[1].tv_sec, spec[1].tv_nsec); - if (retval > 0) { - header.size = retval; - header.type = T_UTIME; - } - break; - case T_RENAME: - oldpath = va_arg(ap, V9fsString *); - path = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ss", oldpath, path); - if (retval > 0) { - header.size = retval; - header.type = T_RENAME; - } - break; - case T_REMOVE: - path = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); - if (retval > 0) { - header.size = retval; - header.type = T_REMOVE; - } - break; - case T_LGETXATTR: - size = va_arg(ap, int); - path = va_arg(ap, V9fsString *); - name = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, - "dss", size, path, name); - if (retval > 0) { - header.size = retval; - header.type = T_LGETXATTR; - } - break; - case T_LLISTXATTR: - size = va_arg(ap, int); - path = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ds", size, path); - if (retval > 0) { - header.size = retval; - header.type = T_LLISTXATTR; - } - break; - case T_LSETXATTR: - path = va_arg(ap, V9fsString *); - name = va_arg(ap, V9fsString *); - value = va_arg(ap, V9fsString *); - size = va_arg(ap, int); - flags = va_arg(ap, int); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "sssdd", - path, name, value, size, flags); - if (retval > 0) { - header.size = retval; - header.type = T_LSETXATTR; - } - break; - case T_LREMOVEXATTR: - path = va_arg(ap, V9fsString *); - name = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "ss", path, name); - if (retval > 0) { - header.size = retval; - header.type = T_LREMOVEXATTR; - } - break; - case T_GETVERSION: - path = va_arg(ap, V9fsString *); - retval = proxy_marshal(iovec, PROXY_HDR_SZ, "s", path); - if (retval > 0) { - header.size = retval; - header.type = T_GETVERSION; - } - break; - default: - error_report("Invalid type %d", type); - retval = -EINVAL; - break; - } - va_end(ap); - - if (retval < 0) { - goto err_out; - } - - /* marshal the header details */ - retval = proxy_marshal(iovec, 0, "dd", header.type, header.size); - assert(retval == 4 * 2); - header.size += PROXY_HDR_SZ; - - retval = qemu_write_full(proxy->sockfd, iovec->iov_base, header.size); - if (retval != header.size) { - goto close_error; - } - - switch (type) { - case T_OPEN: - case T_CREATE: - /* - * A file descriptor is returned as response for - * T_OPEN,T_CREATE on success - */ - if (v9fs_receivefd(proxy->sockfd, &retval) < 0) { - goto close_error; - } - break; - case T_MKNOD: - case T_MKDIR: - case T_SYMLINK: - case T_LINK: - case T_CHMOD: - case T_CHOWN: - case T_RENAME: - case T_TRUNCATE: - case T_UTIME: - case T_REMOVE: - case T_LSETXATTR: - case T_LREMOVEXATTR: - if (v9fs_receive_status(proxy, reply, &retval) < 0) { - goto close_error; - } - break; - case T_LSTAT: - case T_READLINK: - case T_STATFS: - case T_GETVERSION: - if (v9fs_receive_response(proxy, type, &retval, response) < 0) { - goto close_error; - } - break; - case T_LGETXATTR: - case T_LLISTXATTR: - if (!size) { - if (v9fs_receive_status(proxy, reply, &retval) < 0) { - goto close_error; - } - } else { - if (v9fs_receive_response(proxy, type, &retval, response) < 0) { - goto close_error; - } - } - break; - } - -err_out: - qemu_mutex_unlock(&proxy->mutex); - return retval; - -close_error: - close(proxy->sockfd); - proxy->sockfd = -1; - qemu_mutex_unlock(&proxy->mutex); - return -EIO; -} - -static int proxy_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) -{ - int retval; - retval = v9fs_request(fs_ctx->private, T_LSTAT, stbuf, fs_path); - if (retval < 0) { - errno = -retval; - return -1; - } - return retval; -} - -static ssize_t proxy_readlink(FsContext *fs_ctx, V9fsPath *fs_path, - char *buf, size_t bufsz) -{ - int retval; - retval = v9fs_request(fs_ctx->private, T_READLINK, buf, fs_path, bufsz); - if (retval < 0) { - errno = -retval; - return -1; - } - return strlen(buf); -} - -static int proxy_close(FsContext *ctx, V9fsFidOpenState *fs) -{ - return close(fs->fd); -} - -static int proxy_closedir(FsContext *ctx, V9fsFidOpenState *fs) -{ - return closedir(fs->dir.stream); -} - -static int proxy_open(FsContext *ctx, V9fsPath *fs_path, - int flags, V9fsFidOpenState *fs) -{ - fs->fd = v9fs_request(ctx->private, T_OPEN, NULL, fs_path, flags); - if (fs->fd < 0) { - errno = -fs->fd; - fs->fd = -1; - } - return fs->fd; -} - -static int proxy_opendir(FsContext *ctx, - V9fsPath *fs_path, V9fsFidOpenState *fs) -{ - int serrno, fd; - - fs->dir.stream = NULL; - fd = v9fs_request(ctx->private, T_OPEN, NULL, fs_path, O_DIRECTORY); - if (fd < 0) { - errno = -fd; - return -1; - } - fs->dir.stream = fdopendir(fd); - if (!fs->dir.stream) { - serrno = errno; - close(fd); - errno = serrno; - return -1; - } - return 0; -} - -static void proxy_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) -{ - rewinddir(fs->dir.stream); -} - -static off_t proxy_telldir(FsContext *ctx, V9fsFidOpenState *fs) -{ - return telldir(fs->dir.stream); -} - -static struct dirent *proxy_readdir(FsContext *ctx, V9fsFidOpenState *fs) -{ - struct dirent *entry; - entry = readdir(fs->dir.stream); -#ifdef CONFIG_DARWIN - if (!entry) { - return NULL; - } - int td; - td = telldir(fs->dir.stream); - /* If telldir fails, fail the entire readdir call */ - if (td < 0) { - return NULL; - } - entry->d_seekoff = td; -#endif - return entry; -} - -static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) -{ - seekdir(fs->dir.stream, off); -} - -static ssize_t proxy_preadv(FsContext *ctx, V9fsFidOpenState *fs, - const struct iovec *iov, - int iovcnt, off_t offset) -{ - ssize_t ret; -#ifdef CONFIG_PREADV - ret = preadv(fs->fd, iov, iovcnt, offset); -#else - ret = lseek(fs->fd, offset, SEEK_SET); - if (ret >= 0) { - ret = readv(fs->fd, iov, iovcnt); - } -#endif - return ret; -} - -static ssize_t proxy_pwritev(FsContext *ctx, V9fsFidOpenState *fs, - const struct iovec *iov, - int iovcnt, off_t offset) -{ - ssize_t ret; - -#ifdef CONFIG_PREADV - ret = pwritev(fs->fd, iov, iovcnt, offset); -#else - ret = lseek(fs->fd, offset, SEEK_SET); - if (ret >= 0) { - ret = writev(fs->fd, iov, iovcnt); - } -#endif -#ifdef CONFIG_SYNC_FILE_RANGE - if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) { - /* - * Initiate a writeback. This is not a data integrity sync. - * We want to ensure that we don't leave dirty pages in the cache - * after write when writeout=immediate is specified. - */ - sync_file_range(fs->fd, offset, ret, - SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE); - } -#endif - return ret; -} - -static int proxy_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) -{ - int retval; - retval = v9fs_request(fs_ctx->private, T_CHMOD, NULL, fs_path, - credp->fc_mode); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_mknod(FsContext *fs_ctx, V9fsPath *dir_path, - const char *name, FsCred *credp) -{ - int retval; - V9fsString fullname; - - v9fs_string_init(&fullname); - v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name); - - retval = v9fs_request(fs_ctx->private, T_MKNOD, NULL, &fullname, - credp->fc_mode, credp->fc_rdev, - credp->fc_uid, credp->fc_gid); - v9fs_string_free(&fullname); - if (retval < 0) { - errno = -retval; - retval = -1; - } - return retval; -} - -static int proxy_mkdir(FsContext *fs_ctx, V9fsPath *dir_path, - const char *name, FsCred *credp) -{ - int retval; - V9fsString fullname; - - v9fs_string_init(&fullname); - v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name); - - retval = v9fs_request(fs_ctx->private, T_MKDIR, NULL, &fullname, - credp->fc_mode, credp->fc_uid, credp->fc_gid); - v9fs_string_free(&fullname); - if (retval < 0) { - errno = -retval; - retval = -1; - } - return retval; -} - -static int proxy_fstat(FsContext *fs_ctx, int fid_type, - V9fsFidOpenState *fs, struct stat *stbuf) -{ - int fd; - - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } - return fstat(fd, stbuf); -} - -static int proxy_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, - int flags, FsCred *credp, V9fsFidOpenState *fs) -{ - V9fsString fullname; - - v9fs_string_init(&fullname); - v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name); - - fs->fd = v9fs_request(fs_ctx->private, T_CREATE, NULL, &fullname, flags, - credp->fc_mode, credp->fc_uid, credp->fc_gid); - v9fs_string_free(&fullname); - if (fs->fd < 0) { - errno = -fs->fd; - fs->fd = -1; - } - return fs->fd; -} - -static int proxy_symlink(FsContext *fs_ctx, const char *oldpath, - V9fsPath *dir_path, const char *name, FsCred *credp) -{ - int retval; - V9fsString fullname, target; - - v9fs_string_init(&fullname); - v9fs_string_init(&target); - - v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name); - v9fs_string_sprintf(&target, "%s", oldpath); - - retval = v9fs_request(fs_ctx->private, T_SYMLINK, NULL, &target, &fullname, - credp->fc_uid, credp->fc_gid); - v9fs_string_free(&fullname); - v9fs_string_free(&target); - if (retval < 0) { - errno = -retval; - retval = -1; - } - return retval; -} - -static int proxy_link(FsContext *ctx, V9fsPath *oldpath, - V9fsPath *dirpath, const char *name) -{ - int retval; - V9fsString newpath; - - v9fs_string_init(&newpath); - v9fs_string_sprintf(&newpath, "%s/%s", dirpath->data, name); - - retval = v9fs_request(ctx->private, T_LINK, NULL, oldpath, &newpath); - v9fs_string_free(&newpath); - if (retval < 0) { - errno = -retval; - retval = -1; - } - return retval; -} - -static int proxy_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size) -{ - int retval; - - retval = v9fs_request(ctx->private, T_TRUNCATE, NULL, fs_path, size); - if (retval < 0) { - errno = -retval; - return -1; - } - return 0; -} - -static int proxy_rename(FsContext *ctx, const char *oldpath, - const char *newpath) -{ - int retval; - V9fsString oldname, newname; - - v9fs_string_init(&oldname); - v9fs_string_init(&newname); - - v9fs_string_sprintf(&oldname, "%s", oldpath); - v9fs_string_sprintf(&newname, "%s", newpath); - retval = v9fs_request(ctx->private, T_RENAME, NULL, &oldname, &newname); - v9fs_string_free(&oldname); - v9fs_string_free(&newname); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) -{ - int retval; - retval = v9fs_request(fs_ctx->private, T_CHOWN, NULL, fs_path, - credp->fc_uid, credp->fc_gid); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_utimensat(FsContext *s, V9fsPath *fs_path, - const struct timespec *buf) -{ - int retval; - retval = v9fs_request(s->private, T_UTIME, NULL, fs_path, - buf[0].tv_sec, buf[0].tv_nsec, - buf[1].tv_sec, buf[1].tv_nsec); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_remove(FsContext *ctx, const char *path) -{ - int retval; - V9fsString name; - v9fs_string_init(&name); - v9fs_string_sprintf(&name, "%s", path); - retval = v9fs_request(ctx->private, T_REMOVE, NULL, &name); - v9fs_string_free(&name); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_fsync(FsContext *ctx, int fid_type, - V9fsFidOpenState *fs, int datasync) -{ - int fd; - - if (fid_type == P9_FID_DIR) { - fd = dirfd(fs->dir.stream); - } else { - fd = fs->fd; - } - - if (datasync) { - return qemu_fdatasync(fd); - } else { - return fsync(fd); - } -} - -static int proxy_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf) -{ - int retval; - retval = v9fs_request(s->private, T_STATFS, stbuf, fs_path); - if (retval < 0) { - errno = -retval; - return -1; - } - return retval; -} - -static ssize_t proxy_lgetxattr(FsContext *ctx, V9fsPath *fs_path, - const char *name, void *value, size_t size) -{ - int retval; - V9fsString xname; - - v9fs_string_init(&xname); - v9fs_string_sprintf(&xname, "%s", name); - retval = v9fs_request(ctx->private, T_LGETXATTR, value, size, fs_path, - &xname); - v9fs_string_free(&xname); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static ssize_t proxy_llistxattr(FsContext *ctx, V9fsPath *fs_path, - void *value, size_t size) -{ - int retval; - retval = v9fs_request(ctx->private, T_LLISTXATTR, value, size, fs_path); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name, - void *value, size_t size, int flags) -{ - int retval; - V9fsString xname, xvalue; - - v9fs_string_init(&xname); - v9fs_string_sprintf(&xname, "%s", name); - - v9fs_string_init(&xvalue); - xvalue.size = size; - xvalue.data = g_malloc(size); - memcpy(xvalue.data, value, size); - - retval = v9fs_request(ctx->private, T_LSETXATTR, value, fs_path, &xname, - &xvalue, size, flags); - v9fs_string_free(&xname); - v9fs_string_free(&xvalue); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_lremovexattr(FsContext *ctx, V9fsPath *fs_path, - const char *name) -{ - int retval; - V9fsString xname; - - v9fs_string_init(&xname); - v9fs_string_sprintf(&xname, "%s", name); - retval = v9fs_request(ctx->private, T_LREMOVEXATTR, NULL, fs_path, &xname); - v9fs_string_free(&xname); - if (retval < 0) { - errno = -retval; - } - return retval; -} - -static int proxy_name_to_path(FsContext *ctx, V9fsPath *dir_path, - const char *name, V9fsPath *target) -{ - if (dir_path) { - v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); - } else { - v9fs_path_sprintf(target, "%s", name); - } - return 0; -} - -static int proxy_renameat(FsContext *ctx, V9fsPath *olddir, - const char *old_name, V9fsPath *newdir, - const char *new_name) -{ - int ret; - V9fsString old_full_name, new_full_name; - - v9fs_string_init(&old_full_name); - v9fs_string_init(&new_full_name); - - v9fs_string_sprintf(&old_full_name, "%s/%s", olddir->data, old_name); - v9fs_string_sprintf(&new_full_name, "%s/%s", newdir->data, new_name); - - ret = proxy_rename(ctx, old_full_name.data, new_full_name.data); - v9fs_string_free(&old_full_name); - v9fs_string_free(&new_full_name); - return ret; -} - -static int proxy_unlinkat(FsContext *ctx, V9fsPath *dir, - const char *name, int flags) -{ - int ret; - V9fsString fullname; - v9fs_string_init(&fullname); - - v9fs_string_sprintf(&fullname, "%s/%s", dir->data, name); - ret = proxy_remove(ctx, fullname.data); - v9fs_string_free(&fullname); - - return ret; -} - -static int proxy_ioc_getversion(FsContext *fs_ctx, V9fsPath *path, - mode_t st_mode, uint64_t *st_gen) -{ - int err; - - /* Do not try to open special files like device nodes, fifos etc - * we can get fd for regular files and directories only - */ - if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) { - errno = ENOTTY; - return -1; - } - err = v9fs_request(fs_ctx->private, T_GETVERSION, st_gen, path); - if (err < 0) { - errno = -err; - err = -1; - } - return err; -} - -static int connect_namedsocket(const char *path, Error **errp) -{ - int sockfd; - struct sockaddr_un helper; - - if (strlen(path) >= sizeof(helper.sun_path)) { - error_setg(errp, "socket name too long"); - return -1; - } - sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sockfd < 0) { - error_setg_errno(errp, errno, "failed to create client socket"); - return -1; - } - strcpy(helper.sun_path, path); - helper.sun_family = AF_UNIX; - if (connect(sockfd, (struct sockaddr *)&helper, sizeof(helper)) < 0) { - error_setg_errno(errp, errno, "failed to connect to '%s'", path); - close(sockfd); - return -1; - } - - /* remove the socket for security reasons */ - unlink(path); - return sockfd; -} - -static void error_append_socket_sockfd_hint(Error *const *errp) -{ - error_append_hint(errp, "Either specify socket=/some/path where /some/path" - " points to a listening AF_UNIX socket or sock_fd=fd" - " where fd is a file descriptor to a connected AF_UNIX" - " socket\n"); -} - -static int proxy_parse_opts(QemuOpts *opts, FsDriverEntry *fs, Error **errp) -{ - const char *socket = qemu_opt_get(opts, "socket"); - const char *sock_fd = qemu_opt_get(opts, "sock_fd"); - - if (!socket && !sock_fd) { - error_setg(errp, "both socket and sock_fd properties are missing"); - error_append_socket_sockfd_hint(errp); - return -1; - } - if (socket && sock_fd) { - error_setg(errp, "both socket and sock_fd properties are set"); - error_append_socket_sockfd_hint(errp); - return -1; - } - if (socket) { - fs->path = g_strdup(socket); - fs->export_flags |= V9FS_PROXY_SOCK_NAME; - } else { - fs->path = g_strdup(sock_fd); - fs->export_flags |= V9FS_PROXY_SOCK_FD; - } - return 0; -} - -static int proxy_init(FsContext *ctx, Error **errp) -{ - V9fsProxy *proxy = g_new(V9fsProxy, 1); - int sock_id; - - if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { - sock_id = connect_namedsocket(ctx->fs_root, errp); - } else { - sock_id = atoi(ctx->fs_root); - if (sock_id < 0) { - error_setg(errp, "socket descriptor not initialized"); - } - } - if (sock_id < 0) { - g_free(proxy); - return -1; - } - g_free(ctx->fs_root); - ctx->fs_root = NULL; - - proxy->in_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); - proxy->in_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; - proxy->out_iovec.iov_base = g_malloc(PROXY_MAX_IO_SZ + PROXY_HDR_SZ); - proxy->out_iovec.iov_len = PROXY_MAX_IO_SZ + PROXY_HDR_SZ; - - ctx->private = proxy; - proxy->sockfd = sock_id; - qemu_mutex_init(&proxy->mutex); - - ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT; - ctx->exops.get_st_gen = proxy_ioc_getversion; - return 0; -} - -static void proxy_cleanup(FsContext *ctx) -{ - V9fsProxy *proxy = ctx->private; - - if (!proxy) { - return; - } - - g_free(proxy->out_iovec.iov_base); - g_free(proxy->in_iovec.iov_base); - if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { - close(proxy->sockfd); - } - g_free(proxy); -} - -FileOperations proxy_ops = { - .parse_opts = proxy_parse_opts, - .init = proxy_init, - .cleanup = proxy_cleanup, - .lstat = proxy_lstat, - .readlink = proxy_readlink, - .close = proxy_close, - .closedir = proxy_closedir, - .open = proxy_open, - .opendir = proxy_opendir, - .rewinddir = proxy_rewinddir, - .telldir = proxy_telldir, - .readdir = proxy_readdir, - .seekdir = proxy_seekdir, - .preadv = proxy_preadv, - .pwritev = proxy_pwritev, - .chmod = proxy_chmod, - .mknod = proxy_mknod, - .mkdir = proxy_mkdir, - .fstat = proxy_fstat, - .open2 = proxy_open2, - .symlink = proxy_symlink, - .link = proxy_link, - .truncate = proxy_truncate, - .rename = proxy_rename, - .chown = proxy_chown, - .utimensat = proxy_utimensat, - .remove = proxy_remove, - .fsync = proxy_fsync, - .statfs = proxy_statfs, - .lgetxattr = proxy_lgetxattr, - .llistxattr = proxy_llistxattr, - .lsetxattr = proxy_lsetxattr, - .lremovexattr = proxy_lremovexattr, - .name_to_path = proxy_name_to_path, - .renameat = proxy_renameat, - .unlinkat = proxy_unlinkat, -}; diff --git a/fsdev/meson.build b/fsdev/meson.build index e20d7255e1e..c751d8cb622 100644 --- a/fsdev/meson.build +++ b/fsdev/meson.build @@ -8,11 +8,3 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( if host_os in ['linux', 'darwin'] system_ss.add_all(fsdev_ss) endif - -if have_virtfs_proxy_helper - executable('virtfs-proxy-helper', - files('virtfs-proxy-helper.c', '9p-marshal.c', '9p-iov-marshal.c'), - dependencies: [qemuutil, libattr, libcap_ng], - install: true, - install_dir: get_option('libexecdir')) -endif diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build index f1b62fa8c80..eceffdb81ea 100644 --- a/hw/9pfs/meson.build +++ b/hw/9pfs/meson.build @@ -2,7 +2,6 @@ fs_ss = ss.source_set() fs_ss.add(files( '9p-local.c', '9p-posix-acl.c', - '9p-proxy.c', '9p-synth.c', '9p-xattr-user.c', '9p-xattr.c', diff --git a/meson_options.txt b/meson_options.txt index 0269fa0f16e..f65fead3161 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -301,8 +301,6 @@ option('vhost_user_blk_server', type: 'feature', value: 'auto', description: 'build vhost-user-blk server') option('virtfs', type: 'feature', value: 'auto', description: 'virtio-9p support') -option('virtfs_proxy_helper', type: 'feature', value: 'auto', - description: 'virtio-9p proxy helper support') option('libvduse', type: 'feature', value: 'auto', description: 'build VDUSE Library') option('vduse_blk_export', type: 'feature', value: 'auto', diff --git a/qemu-options.hx b/qemu-options.hx index d94e2cbbaeb..20a1ce0d43b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1766,29 +1766,18 @@ DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, " [[,throttling.bps-total-max=bm]|[[,throttling.bps-read-max=rm][,throttling.bps-write-max=wm]]]\n" " [[,throttling.iops-total-max=im]|[[,throttling.iops-read-max=irm][,throttling.iops-write-max=iwm]]]\n" " [[,throttling.iops-size=is]]\n" - "-fsdev proxy,id=id,socket=socket[,writeout=immediate][,readonly=on]\n" - "-fsdev proxy,id=id,sock_fd=sock_fd[,writeout=immediate][,readonly=on]\n" "-fsdev synth,id=id\n", QEMU_ARCH_ALL) SRST ``-fsdev local,id=id,path=path,security_model=security_model [,writeout=writeout][,readonly=on][,fmode=fmode][,dmode=dmode] [,throttling.option=value[,throttling.option=value[,...]]]`` \ -``-fsdev proxy,id=id,socket=socket[,writeout=writeout][,readonly=on]`` - \ -``-fsdev proxy,id=id,sock_fd=sock_fd[,writeout=writeout][,readonly=on]`` - \ ``-fsdev synth,id=id[,readonly=on]`` Define a new file system device. Valid options are: ``local`` Accesses to the filesystem are done by QEMU. - ``proxy`` - Accesses to the filesystem are done by virtfs-proxy-helper(1). This - option is deprecated (since QEMU 8.1) and will be removed in a future - version of QEMU. Use ``local`` instead. - ``synth`` Synthetic filesystem, only used by QTests. @@ -1813,8 +1802,6 @@ SRST security model is same as passthrough except the sever won't report failures if it fails to set file attributes like ownership. Security model is mandatory only for local fsdriver. - Other fsdrivers (like proxy) don't take security model as a - parameter. ``writeout=writeout`` This is an optional argument. The only supported value is @@ -1827,16 +1814,6 @@ SRST Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. - ``socket=socket`` - Enables proxy filesystem driver to use passed socket file for - communicating with virtfs-proxy-helper(1). - - ``sock_fd=sock_fd`` - Enables proxy filesystem driver to use passed socket descriptor - for communicating with virtfs-proxy-helper(1). Usually a helper - like libvirt will create socketpair and pass one of the fds as - sock\_fd. - ``fmode=fmode`` Specifies the default mode for newly created files on the host. Works only with security models "mapped-xattr" and @@ -1889,18 +1866,12 @@ ERST DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, "-virtfs local,path=path,mount_tag=tag,security_model=mapped-xattr|mapped-file|passthrough|none\n" " [,id=id][,writeout=immediate][,readonly=on][,fmode=fmode][,dmode=dmode][,multidevs=remap|forbid|warn]\n" - "-virtfs proxy,mount_tag=tag,socket=socket[,id=id][,writeout=immediate][,readonly=on]\n" - "-virtfs proxy,mount_tag=tag,sock_fd=sock_fd[,id=id][,writeout=immediate][,readonly=on]\n" "-virtfs synth,mount_tag=tag[,id=id][,readonly=on]\n", QEMU_ARCH_ALL) SRST ``-virtfs local,path=path,mount_tag=mount_tag ,security_model=security_model[,writeout=writeout][,readonly=on] [,fmode=fmode][,dmode=dmode][,multidevs=multidevs]`` \ -``-virtfs proxy,socket=socket,mount_tag=mount_tag [,writeout=writeout][,readonly=on]`` - \ -``-virtfs proxy,sock_fd=sock_fd,mount_tag=mount_tag [,writeout=writeout][,readonly=on]`` - \ ``-virtfs synth,mount_tag=mount_tag`` Define a new virtual filesystem device and expose it to the guest using a virtio-9p-device (a.k.a. 9pfs), which essentially means that a certain @@ -1917,11 +1888,6 @@ SRST ``local`` Accesses to the filesystem are done by QEMU. - ``proxy`` - Accesses to the filesystem are done by virtfs-proxy-helper(1). - This option is deprecated (since QEMU 8.1) and will be removed in a - future version of QEMU. Use ``local`` instead. - ``synth`` Synthetic filesystem, only used by QTests. @@ -1946,8 +1912,6 @@ SRST security model is same as passthrough except the sever won't report failures if it fails to set file attributes like ownership. Security model is mandatory only for local fsdriver. - Other fsdrivers (like proxy) don't take security model as a - parameter. ``writeout=writeout`` This is an optional argument. The only supported value is @@ -1960,16 +1924,6 @@ SRST Enables exporting 9p share as a readonly mount for guests. By default read-write access is given. - ``socket=socket`` - Enables proxy filesystem driver to use passed socket file for - communicating with virtfs-proxy-helper(1). Usually a helper like - libvirt will create socketpair and pass one of the fds as - sock\_fd. - - ``sock_fd`` - Enables proxy filesystem driver to use passed 'sock\_fd' as the - socket descriptor for interfacing with virtfs-proxy-helper(1). - ``fmode=fmode`` Specifies the default mode for newly created files on the host. Works only with security models "mapped-xattr" and diff --git a/scripts/meson-buildoptions. b/scripts/meson-buildoptions. new file mode 100644 index 00000000000..e69de29bb2d diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index c97079a38c9..19626b7b464 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -206,8 +206,6 @@ meson_options_help() { printf "%s\n" ' vhost-vdpa vhost-vdpa kernel backend support' printf "%s\n" ' virglrenderer virgl rendering support' printf "%s\n" ' virtfs virtio-9p support' - printf "%s\n" ' virtfs-proxy-helper' - printf "%s\n" ' virtio-9p proxy helper support' printf "%s\n" ' vmdk vmdk image format support' printf "%s\n" ' vmnet vmnet.framework network backend support' printf "%s\n" ' vnc VNC server' @@ -533,8 +531,6 @@ _meson_option_parse() { --disable-virglrenderer) printf "%s" -Dvirglrenderer=disabled ;; --enable-virtfs) printf "%s" -Dvirtfs=enabled ;; --disable-virtfs) printf "%s" -Dvirtfs=disabled ;; - --enable-virtfs-proxy-helper) printf "%s" -Dvirtfs_proxy_helper=enabled ;; - --disable-virtfs-proxy-helper) printf "%s" -Dvirtfs_proxy_helper=disabled ;; --enable-vmdk) printf "%s" -Dvmdk=enabled ;; --disable-vmdk) printf "%s" -Dvmdk=disabled ;; --enable-vmnet) printf "%s" -Dvmnet=enabled ;; From patchwork Wed Sep 11 12:33:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13800489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48E0AEE499F for ; Wed, 11 Sep 2024 12:38:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soMYu-0001uK-BQ; Wed, 11 Sep 2024 08:35:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYU-0000H7-5r for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soMYS-00017c-QR for qemu-devel@nongnu.org; Wed, 11 Sep 2024 08:34:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726058080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+s8ozgP3DcLfD8jX3L8PdVl6oakdD8m+hmmFQEParW8=; b=IUiKAv58fflowQ0daAxDaJOOX7iw1Bteb+VkXiLz8LPSD0aTWgOnVl+EJfFkn6LBmV3+US VU7nhYK7UYBUtgNA4nAeicS12rZtf60dcpiFBuvmZ0pcwmQwQ++jzUProRErj4F+vwEfrG 5KDv0oowp/dpwzjQ7jmNJ9wO0lSDY8Y= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-9RHEHVGcMoOdxoKmMJcgLA-1; Wed, 11 Sep 2024 08:34:39 -0400 X-MC-Unique: 9RHEHVGcMoOdxoKmMJcgLA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-42cb6ed7f9dso30854565e9.3 for ; Wed, 11 Sep 2024 05:34:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726058077; x=1726662877; 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=+s8ozgP3DcLfD8jX3L8PdVl6oakdD8m+hmmFQEParW8=; b=N0WNj3WDFzBWhQkiyG8C+xrSolkqcfVVRHeNC2FZgy9hICheMxguiFzPAp3QorS+nt 0WHYrVJ7b9+IDAN8oMeen/7O1quMfV1bAc3Y3zh0Fm/yKyuCjhH3/fUcSj2bfaT674A3 9LRMI81LpbMhaQyAYwsvF57T87Xkh1yvUM74csUhkSZOtwcbH3/cH6dfWZ5TkQWaiTwO YIW+8TaXaTuiwrJuK/QueMJdXkDW5pK4Q6k9aZyuWYSUbx99m7yE5zidbgNMg1UYsFYd gcI3Eok9oR4Em1s2vBwU7XF6Jhc/kpRVPdD3sy6PWFS2l/XYcJKrwVYxetWTyMqWhXIg sXig== X-Gm-Message-State: AOJu0YzCVS8dhfAX9D1IS/kxD99xFoYQaRbLVfexR3mJXQwnwJngDXpo 5GQSuE55TaWWJs5H374LdfUvVsPHdUwgoCgWnf/cDhwIHM7m/PxkEWPgyeIJFtsahCvVwyyWBOb XFOIImXQTCQn2j4shp21gh68parMZv/7tV1vZr4YELiRIyWm8KcF4GSukcR4u7w8GgKd1IsJn0j ILEJGfWgNfe8Uuf6XTYrnpW3uZYhqKIbywcz1MFWc= X-Received: by 2002:a05:600c:4449:b0:42c:b52b:4349 with SMTP id 5b1f17b1804b1-42cb52b45a0mr110784035e9.33.1726058077313; Wed, 11 Sep 2024 05:34:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLJHmQLLPlLTiGLYkydQNnTc1h66Qf5WU2jEeOdW0sDC+aylLsa8N2YMpSiszvDnb0hHLgKA== X-Received: by 2002:a05:600c:4449:b0:42c:b52b:4349 with SMTP id 5b1f17b1804b1-42cb52b45a0mr110783685e9.33.1726058076804; Wed, 11 Sep 2024 05:34:36 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d367csm11329540f8f.68.2024.09.11.05.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 05:34:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 17/17] minikconf: print error entirely on stderr Date: Wed, 11 Sep 2024 14:33:42 +0200 Message-ID: <20240911123342.339482-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911123342.339482-1-pbonzini@redhat.com> References: <20240911123342.339482-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.144, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org While debugging an invalid configuration, I noticed that the clauses debug ends up on stderr but the header ("The following clauses were found..." ends up on stdout. This makes the contents of meson-logs/meson-log.txt a bit confusing. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- scripts/minikconf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/minikconf.py b/scripts/minikconf.py index bcd91015d34..6f7f43b2918 100644 --- a/scripts/minikconf.py +++ b/scripts/minikconf.py @@ -112,7 +112,7 @@ def has_value(self): def set_value(self, val, clause): self.clauses_for_var.append(clause) if self.has_value() and self.value != val: - print("The following clauses were found for " + self.name) + print("The following clauses were found for " + self.name, file=sys.stderr) for i in self.clauses_for_var: print(" " + str(i), file=sys.stderr) raise KconfigDataError('contradiction between clauses when setting %s' % self)