From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: virtio-dev-return-7165-cohuck=redhat.com@lists.oasis-open.org Sender: List-Post: List-Help: List-Unsubscribe: List-Subscribe: Received: from lists.oasis-open.org (oasis-open.org [10.110.1.242]) by lists.oasis-open.org (Postfix) with ESMTP id 9A6319860A0 for ; Fri, 24 Apr 2020 16:24:17 +0000 (UTC) From: Alexander Duyck Date: Fri, 24 Apr 2020 09:24:14 -0700 Message-ID: <20200424162103.6681.436.stgit@localhost.localdomain> MIME-Version: 1.0 Subject: [virtio-dev] [PATCH v2] virtio-balloon: Disable free page reporting if page poison reporting is not enabled Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit To: jasowang@redhat.com, mst@redhat.com, david@redhat.com Cc: virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org List-ID: From: Alexander Duyck We should disable free page reporting if page poisoning is enabled in the kernel but we cannot report it via the balloon interface. This way we can avoid the possibility of corrupting guest memory. Normally the page poison reporting feature should always be present when free page reporting is enabled on the hypervisor, however this allows us to correctly handle a case of the virtio-balloon device being possibly misconfigured. Fixes: 5d757c8d518d ("virtio-balloon: add support for providing free page reports to host") Signed-off-by: Alexander Duyck --- Changes since v1: Originally this patch also modified free page hinting, that has been removed. Updated patch title and description. Added a comment explaining reasoning for disabling free page reporting. drivers/virtio/virtio_balloon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 51086a5afdd4..1f157d2f4952 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -1107,11 +1107,18 @@ static int virtballoon_restore(struct virtio_device *vdev) static int virtballoon_validate(struct virtio_device *vdev) { - /* Tell the host whether we care about poisoned pages. */ + /* + * Inform the hypervisor that our pages are poisoned or + * initialized. If we cannot do that then we should disable + * page reporting as it could potentially change the contents + * of our free pages. + */ if (!want_init_on_free() && (IS_ENABLED(CONFIG_PAGE_POISONING_NO_SANITY) || !page_poisoning_enabled())) __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_PAGE_POISON); + else if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_REPORTING); __virtio_clear_bit(vdev, VIRTIO_F_IOMMU_PLATFORM); return 0; --------------------------------------------------------------------- To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Duyck Subject: [PATCH v2] virtio-balloon: Disable free page reporting if page poison reporting is not enabled Date: Fri, 24 Apr 2020 09:24:14 -0700 Message-ID: <20200424162103.6681.436.stgit@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Return-path: Sender: List-Post: List-Help: List-Unsubscribe: List-Subscribe: To: jasowang@redhat.com, mst@redhat.com, david@redhat.com Cc: virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org List-Id: virtualization@lists.linuxfoundation.org From: Alexander Duyck We should disable free page reporting if page poisoning is enabled in the kernel but we cannot report it via the balloon interface. This way we can avoid the possibility of corrupting guest memory. Normally the page poison reporting feature should always be present when free page reporting is enabled on the hypervisor, however this allows us to correctly handle a case of the virtio-balloon device being possibly misconfigured. Fixes: 5d757c8d518d ("virtio-balloon: add support for providing free page reports to host") Signed-off-by: Alexander Duyck --- Changes since v1: Originally this patch also modified free page hinting, that has been removed. Updated patch title and description. Added a comment explaining reasoning for disabling free page reporting. drivers/virtio/virtio_balloon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 51086a5afdd4..1f157d2f4952 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -1107,11 +1107,18 @@ static int virtballoon_restore(struct virtio_device *vdev) static int virtballoon_validate(struct virtio_device *vdev) { - /* Tell the host whether we care about poisoned pages. */ + /* + * Inform the hypervisor that our pages are poisoned or + * initialized. If we cannot do that then we should disable + * page reporting as it could potentially change the contents + * of our free pages. + */ if (!want_init_on_free() && (IS_ENABLED(CONFIG_PAGE_POISONING_NO_SANITY) || !page_poisoning_enabled())) __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_PAGE_POISON); + else if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) + __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_REPORTING); __virtio_clear_bit(vdev, VIRTIO_F_IOMMU_PLATFORM); return 0;