Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1540287ybg; Thu, 11 Jun 2020 12:29:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM2V2p4Q0u2VKhiXbF/iFlQzkc6T7qxrEo5c87X9b5BT0yVCaI+eH1xvcP5kX27c97WlfK X-Received: by 2002:a05:6402:155:: with SMTP id s21mr8144982edu.144.1591903741100; Thu, 11 Jun 2020 12:29:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591903741; cv=none; d=google.com; s=arc-20160816; b=0Ucu77Uy3slimPveGX/KmdY747WCl89jgS78vhHHu7xO81xe1qnOCZr7wsb/8e8NHv 7ND0BAzmKWh7Dzh0CviBCd4Wed9fS5cvhBSPiWMQQDAZoI14TT38jzREABegDELRaZY+ BPpB05APA1zpyaBv0jQXZ1al1NJndon7hbQgB4IjzHK1Xot2ptr4722PC/HlxpgpxzAX qOVnAkxrxcwAGD49kdduFCuPg5hNSXg+sjmzUqdBz2y6gWnAB3z8av+gDtiojjBJlOaB yfWFuU5wmBFvSUIguXDFx56bfnJ3UO9nOkDPqAnefdS1vlqvcTGXjSfAtzUwOQJur2x5 0LEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=2l2eSdBqJum9TFb5iBYuRa8B8B3NX05NjbHxGSSWmGQ=; b=avghL/JANTpE8KSwG/qHFZepmjky5Kn8IU9AUxNhDfB039Nv+QPXz4Yc3h2DdXhe+L +2oE+zP8cl5W2q5H6pVAhfIJ9+bJJSehgd1h3s91wkWiJpNnsZIMU1yE5UAF14e5L6pT VvvagepEe9rkq98HcgmulxXZdqklqIe8LMld+EnQ8hQ7rCWuaIdFtd2sFQuuA5gwjS6B T8RudPPz6GGFIKjTwEzT9N82+dfg0oHIPjvBmuV9465Hyw36GgJMoyAhlUi1GWXm6PZ0 1AJR5Zpfw03hK4xFHWBpiPkI8fRwI2AKVbezEKZ86IoGVdFqND8rxn5SmuiUWAULiKv9 YlGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=stnQuEF9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z22si2629232ejr.510.2020.06.11.12.28.38; Thu, 11 Jun 2020 12:29:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=stnQuEF9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727104AbgFKTUe (ORCPT + 99 others); Thu, 11 Jun 2020 15:20:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726832AbgFKTUb (ORCPT ); Thu, 11 Jun 2020 15:20:31 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1258BC08C5C2 for ; Thu, 11 Jun 2020 12:20:31 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id a127so3081643pfa.12 for ; Thu, 11 Jun 2020 12:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=2l2eSdBqJum9TFb5iBYuRa8B8B3NX05NjbHxGSSWmGQ=; b=stnQuEF9g7MtyvCfbMgM4BZG5iEAgUHNwC3emgxuLm1ip4odsE+X2eQ+B/CMZNnSLX h+E+21nnmJwDZLgetRoLzam+qDmI2n0Yt34BqilXHoA6SsR2XQEKy9wsQq6X9sYE6B+z 8gnM/lzQ+/kH9Z9QQW9vyRUCgWW7Ov80VsWbasgZtmjGolYPnredfhVJYxqKMgK3WU8G mD7kyMPrDvxDxlhx7XxOzxsqnaRfGODeN4mRAeKAk5e/u7yEu7JFYqZqT2t6eGYCQeVO fUuxbdATffVa1AiHSlH5YnK9xERQotMeX0fy9zMSsKsAUxTToCn9bppApI0lPwyKKUD+ UIgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=2l2eSdBqJum9TFb5iBYuRa8B8B3NX05NjbHxGSSWmGQ=; b=jThDO8/h9/vVkXr4nGekat6CNB5/7900p0OQIYiANqw7RUk27hOj1OdvR7HFk5gAZ5 fVN0XSdpXBHUyJrw60F5HDgpL+QpaO6z3SaMBELa0xzzaX3kkDIflYOgYaqDFJYpXp8C /E/skaV3KuflUtaE616kQNDF79X7XgTKzvp5FJUu7jw/2XKIDz1mV9qbklkephWcTS3S U33rFlqLWGeQXtYrrE+pOVIDGiSV4wx1h8iLCFzHFv/y4FMQ2nidPDIxUhFQ6bnFRpQW DUmoeoNmoZwrABG8A8OWZz091pYtdW2shhJ30V1Ue0vcTrPgZlJtkPleyk+WE4JCYbo2 DdYg== X-Gm-Message-State: AOAM531EEAYsvkk3JRpTPGKT4Mur96D8H2HKPvWRF621E9OQUOPVLYOT sORXursmUtNZdxDI3io2feRsiw== X-Received: by 2002:a63:1624:: with SMTP id w36mr8043260pgl.144.1591903230513; Thu, 11 Jun 2020 12:20:30 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id u61sm3468710pjb.7.2020.06.11.12.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 12:20:29 -0700 (PDT) Date: Thu, 11 Jun 2020 12:20:29 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Christoph Hellwig cc: Thomas Lendacky , Brijesh Singh , Marek Szyprowski , Robin Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [patch for-5.8 2/4] dma-direct: re-encrypt memory if dma_direct_alloc_pages() fails In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If arch_dma_set_uncached() fails after memory has been decrypted, it needs to be re-encrypted before freeing. Fixes: fa7e2247c572 ("dma-direct: make uncached_kernel_address more general") Cc: stable@vger.kernel.org # 5.7 Signed-off-by: David Rientjes --- kernel/dma/direct.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -220,7 +220,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size, arch_dma_prep_coherent(page, size); ret = arch_dma_set_uncached(ret, size); if (IS_ERR(ret)) - goto out_free_pages; + goto out_encrypt_pages; } done: if (force_dma_unencrypted(dev)) @@ -228,6 +228,10 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size, else *dma_handle = phys_to_dma(dev, page_to_phys(page)); return ret; +out_encrypt_pages: + if (force_dma_unencrypted(dev)) + set_memory_encrypted((unsigned long)page_address(page), + 1 << get_order(size)); out_free_pages: dma_free_contiguous(dev, page, size); return NULL;