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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 884BDC6FA8E for ; Thu, 2 Mar 2023 11:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbjCBLfs (ORCPT ); Thu, 2 Mar 2023 06:35:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbjCBLfe (ORCPT ); Thu, 2 Mar 2023 06:35:34 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9509B1517F for ; Thu, 2 Mar 2023 03:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677756880; 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=nMUvg2hEs0iMx2dm3/Jg9b5hv2Rlumo7TQ+47EWr+7I=; b=eqM4MKD4lbhRF16c0egtl+jxhsbdRBQsXRI4OHQkwG+VozXKm3UxGokgCw0Zq5uPLEPCfu NXl5vgLB/aDOCv+Zsp8zMHfkgbP7oZcEWgWf/q/o3GiDfb2GTqItxf4LidNxasFa+rhfYz 2ej4Im32XE4zOHKneIupZ+1GCn7w7rM= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-634-6luZiEUZPIePmsJYjtSOYg-1; Thu, 02 Mar 2023 06:34:39 -0500 X-MC-Unique: 6luZiEUZPIePmsJYjtSOYg-1 Received: by mail-qv1-f69.google.com with SMTP id y3-20020a0cec03000000b0056ee5b123bbso8740724qvo.7 for ; Thu, 02 Mar 2023 03:34:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677756879; 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=nMUvg2hEs0iMx2dm3/Jg9b5hv2Rlumo7TQ+47EWr+7I=; b=Ulh+wiMhKXTnEjeOJLA/7uXFxjN8HBI+5E/aMRxir6f8kh9FgPchZy+AQw8htRF+WV +co6DCjbWvxpW+KP+QbTp6Jae7mFWHxG4yVstkVpA9trLJ5pOlZdOxScmn0ceLQ8cx85 nL20Mp07tqzyBVnr3DLgie4+MWhhQkmp9RdA6UxSYyFfYImeaNzOUcHJ84ixGyRhFRDM doiB6T8yC6uBIFHUuEFrMibW/Yzskzclu2HIPgsRfaBlwOnmf9yW1QsyD/rjqUoY+5dX jqFGAWOtjg7EkpD20UuHG8J52OU4RwulQpWHUJNMfaPoI+xJ6zS2B76P7NaQEujXzrDy k6Xw== X-Gm-Message-State: AO0yUKW3PejyuFnr4P57wWa4Exk01yf59/w58wFk386xA9VT9wfOVp0n wI/AelEh1KBCUlAOI3LAShk9HKDEnCVNfwVkKhHoCA1vHVmrJjLI+qRIA8oZ3LzKV2JXf9dZCld N6WDJgHyZVw/xDZviFsEIjRgX X-Received: by 2002:ac8:5850:0:b0:3bf:d6ad:5236 with SMTP id h16-20020ac85850000000b003bfd6ad5236mr15655317qth.32.1677756879136; Thu, 02 Mar 2023 03:34:39 -0800 (PST) X-Google-Smtp-Source: AK7set9TavRztcG0ZSYQlhYEtTPhNvB2VmTMeHABCwp3UyKfmeGcD6URaSgRaErRo454+a/9s5fAlA== X-Received: by 2002:ac8:5850:0:b0:3bf:d6ad:5236 with SMTP id h16-20020ac85850000000b003bfd6ad5236mr15655295qth.32.1677756878884; Thu, 02 Mar 2023 03:34:38 -0800 (PST) Received: from step1.redhat.com (c-115-213.cust-q.wadsl.it. [212.43.115.213]) by smtp.gmail.com with ESMTPSA id o12-20020ac8698c000000b003ba19e53e43sm10084156qtq.25.2023.03.02.03.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 03:34:38 -0800 (PST) From: Stefano Garzarella To: virtualization@lists.linux-foundation.org Cc: Andrey Zhadchenko , eperezma@redhat.com, netdev@vger.kernel.org, stefanha@redhat.com, linux-kernel@vger.kernel.org, Jason Wang , "Michael S. Tsirkin" , kvm@vger.kernel.org, Stefano Garzarella Subject: [PATCH v2 3/8] vringh: replace kmap_atomic() with kmap_local_page() Date: Thu, 2 Mar 2023 12:34:16 +0100 Message-Id: <20230302113421.174582-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230302113421.174582-1-sgarzare@redhat.com> References: <20230302113421.174582-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kmap_atomic() is deprecated in favor of kmap_local_page(). With kmap_local_page() the mappings are per thread, CPU local, can take page-faults, and can be called from any context (including interrupts). Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. kmap_atomic() is implemented like a kmap_local_page() which also disables page-faults and preemption (the latter only for !PREEMPT_RT kernels, otherwise it only disables migration). The code within the mappings/un-mappings in getu16_iotlb() and putu16_iotlb() don't depend on the above-mentioned side effects of kmap_atomic(), so that mere replacements of the old API with the new one is all that is required (i.e., there is no need to explicitly add calls to pagefault_disable() and/or preempt_disable()). Signed-off-by: Stefano Garzarella --- Notes: v2: - added this patch since checkpatch.pl complained about deprecation of kmap_atomic() touched by next patch drivers/vhost/vringh.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c index a1e27da54481..0ba3ef809e48 100644 --- a/drivers/vhost/vringh.c +++ b/drivers/vhost/vringh.c @@ -1220,10 +1220,10 @@ static inline int getu16_iotlb(const struct vringh *vrh, if (ret < 0) return ret; - kaddr = kmap_atomic(iov.bv_page); + kaddr = kmap_local_page(iov.bv_page); from = kaddr + iov.bv_offset; *val = vringh16_to_cpu(vrh, READ_ONCE(*(__virtio16 *)from)); - kunmap_atomic(kaddr); + kunmap_local(kaddr); return 0; } @@ -1241,10 +1241,10 @@ static inline int putu16_iotlb(const struct vringh *vrh, if (ret < 0) return ret; - kaddr = kmap_atomic(iov.bv_page); + kaddr = kmap_local_page(iov.bv_page); to = kaddr + iov.bv_offset; WRITE_ONCE(*(__virtio16 *)to, cpu_to_vringh16(vrh, val)); - kunmap_atomic(kaddr); + kunmap_local(kaddr); return 0; } -- 2.39.2