From patchwork Fri Jun 2 13:52:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 101260 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp205137obc; Fri, 2 Jun 2017 06:55:41 -0700 (PDT) X-Received: by 10.84.208.236 with SMTP id c41mr32021plj.95.1496411741815; Fri, 02 Jun 2017 06:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496411741; cv=none; d=google.com; s=arc-20160816; b=aTZSflTAFbM8Y0MG3YN1/hkPiElvWeuCMCqB+0FpmpWn0jp7tAMzSFHqRliAYLfDZn NMkdxIYP0cbB5tjwi4Gtd73mFDpHqVrybUqrIhHi8aapG/fwyS4CPVqQ5eDKVOrDrLA/ 7xTKFkEi6N9gk8Yf92XG4A69h23W498IgqO48I+IVBVX+Xlig963wGTt/gHWqsxY7yRJ ugsEkh4hTdrJE2R9f29pH+svdSp+BWFOgEI/pWrobG0hKTL4sLNnl1Y2v4DLyxHrAduw 2YqtVt18/Oi6N1CsUpnGo0bjdyfHBapdJtp1rEkI3zUV65JfjkN1MRuDoHqUqLMSpW8K PhCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=REUIvN9OMPV4fUP3gDNzmU+RlKc1AfnjypgmiHJnst4=; b=WJfzcT2+fYx8qaH6Jf2+EckpBDGVjuANonc5HGAWaLzzgxLKXzAneQGtyeh7qlMjic NNooUkoFfGKqyAuuhf2LxkPzzd/SqPRGO9kkJU5pDusDBDvyqXgBuML6iJ9sOLnbWkuv Dxd6mSyvXsfc+pit5gakn1K1CQvI6jmnzrcJT7bZNlvVWKPdJrCF0dGjreFkfffl6Ebh B2BbXHdyXjaGU4npj49V07awmhPxXm9Cu5yRsqe4GsiLX6N1BmdCGc2FlCUTZ85NoAcl VMKCG/8pBOxg+vmtfNkpR4GOomC1J/ZF/T/bgBg0J7XEP3PY9UYJK7bW8APFWCbjQFo+ hG1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si3183385pgj.43.2017.06.02.06.55.41; Fri, 02 Jun 2017 06:55:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751611AbdFBNzV (ORCPT + 2 others); Fri, 2 Jun 2017 09:55:21 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:36674 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751597AbdFBNzT (ORCPT ); Fri, 2 Jun 2017 09:55:19 -0400 Received: by mail-wm0-f49.google.com with SMTP id 7so26355828wmo.1 for ; Fri, 02 Jun 2017 06:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=esFDaoQnflXguuSmAmJsAcYBe+fXr0flrf1fGkfahXY=; b=gIdCQUJjRfRkvFcdK08bomGle2qrK8A5nqe6rgY80M2HuL6p/BMPOdALnW9NAlz8iq Jltup8UkGYWp/a8LlMkS9/VZ+2+mzl94FsCBzDZnE5BqQ2FYFwlkTF24jUJmLnBob8xz mWRmuclAD3DB1mZ5nxedrsO/aAeHR9p+TPNkA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=esFDaoQnflXguuSmAmJsAcYBe+fXr0flrf1fGkfahXY=; b=nOGb4Y//1yk/Fcp3DvryBJCuYelphSb42GpLu2J9SBjmYC+d/Ryr+LNAiHqzb0JbL/ fn1OmB8JcVIvVana6mQE2yG2jqmQ59rddEsjPEmkIxiTuLtNiaM5T6AjBjcSgNwo2A9f 4LDHI32EP1B/m4Om6ETUFpuIFSOeAGrNu4TYN4FNVk6y1uA8a4Htt7sWMr1Qm3kVdYAm IPdxDwXoFPiTi2ZaT188BDnRmELz6oC+JE6XFMv3+TRCF6S5VYNCE/E0hrjS9xQhEsld 1UYHeJoqFX/U4nDw/FC6w9Gda9aHnvPWlnVzAwwYiEKq27nhlJXqfhWXQm3Xkn45yYqq r/cA== X-Gm-Message-State: AODbwcDRlHdSDxaQE3CVEY3py9Ne/pUxlkWvwRMiKJr78J+CGa/PmLK+ GJ3NL+LOwn8MA8MAFxMaeQ== X-Received: by 10.80.179.209 with SMTP id t17mr6208230edd.62.1496411702379; Fri, 02 Jun 2017 06:55:02 -0700 (PDT) Received: from localhost.localdomain ([105.151.155.95]) by smtp.gmail.com with ESMTPSA id g48sm9756076edc.8.2017.06.02.06.55.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:55:01 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Matt Fleming Subject: [PATCH 09/13] efi/capsule-loader: Use page addresses rather than struct page pointers Date: Fri, 2 Jun 2017 13:52:03 +0000 Message-Id: <20170602135207.21708-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170602135207.21708-1-ard.biesheuvel@linaro.org> References: <20170602135207.21708-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org To give some leeway to code that handles non-standard capsule headers, let's keep an array of page addresses rather than struct page pointers. This gives special implementations of efi_capsule_setup_info() the opportunity to mangle the payload a bit before it is presented to the firmware, without putting any knowledge of the nature of such quirks into the generic code. Cc: Matt Fleming Tested-by: "Bryan O'Donoghue" Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/capsule-loader.c | 12 ++++++++---- drivers/firmware/efi/capsule.c | 7 ++++--- include/linux/efi.h | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/efi/capsule-loader.c b/drivers/firmware/efi/capsule-loader.c index cbc3526953d5..ec8ac5c4dd84 100644 --- a/drivers/firmware/efi/capsule-loader.c +++ b/drivers/firmware/efi/capsule-loader.c @@ -20,6 +20,10 @@ #define NO_FURTHER_WRITE_ACTION -1 +#ifndef phys_to_page +#define phys_to_page(x) pfn_to_page((x) >> PAGE_SHIFT) +#endif + /** * efi_free_all_buff_pages - free all previous allocated buffer pages * @cap_info: pointer to current instance of capsule_info structure @@ -31,7 +35,7 @@ static void efi_free_all_buff_pages(struct capsule_info *cap_info) { while (cap_info->index > 0) - __free_page(cap_info->pages[--cap_info->index]); + __free_page(phys_to_page(cap_info->pages[--cap_info->index])); cap_info->index = NO_FURTHER_WRITE_ACTION; } @@ -161,12 +165,12 @@ static ssize_t efi_capsule_write(struct file *file, const char __user *buff, goto failed; } - cap_info->pages[cap_info->index++] = page; + cap_info->pages[cap_info->index++] = page_to_phys(page); cap_info->page_bytes_remain = PAGE_SIZE; + } else { + page = phys_to_page(cap_info->pages[cap_info->index - 1]); } - page = cap_info->pages[cap_info->index - 1]; - kbuff = kmap(page); kbuff += PAGE_SIZE - cap_info->page_bytes_remain; diff --git a/drivers/firmware/efi/capsule.c b/drivers/firmware/efi/capsule.c index e603ccf39d80..901b9306bf94 100644 --- a/drivers/firmware/efi/capsule.c +++ b/drivers/firmware/efi/capsule.c @@ -214,7 +214,7 @@ efi_capsule_update_locked(efi_capsule_header_t *capsule, * * Return 0 on success, a converted EFI status code on failure. */ -int efi_capsule_update(efi_capsule_header_t *capsule, struct page **pages) +int efi_capsule_update(efi_capsule_header_t *capsule, phys_addr_t *pages) { u32 imagesize = capsule->imagesize; efi_guid_t guid = capsule->guid; @@ -249,10 +249,11 @@ int efi_capsule_update(efi_capsule_header_t *capsule, struct page **pages) sglist = kmap(sg_pages[i]); for (j = 0; j < SGLIST_PER_PAGE && count > 0; j++) { - u64 sz = min_t(u64, imagesize, PAGE_SIZE); + u64 sz = min_t(u64, imagesize, + PAGE_SIZE - (u64)*pages % PAGE_SIZE); sglist[j].length = sz; - sglist[j].data = page_to_phys(*pages++); + sglist[j].data = *pages++; imagesize -= sz; count--; diff --git a/include/linux/efi.h b/include/linux/efi.h index a7379a2b5680..8269bcb8ccf7 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -143,7 +143,7 @@ struct capsule_info { long index; size_t count; size_t total_size; - struct page **pages; + phys_addr_t *pages; size_t page_bytes_remain; }; @@ -1415,7 +1415,7 @@ extern int efi_capsule_supported(efi_guid_t guid, u32 flags, size_t size, int *reset); extern int efi_capsule_update(efi_capsule_header_t *capsule, - struct page **pages); + phys_addr_t *pages); #ifdef CONFIG_EFI_RUNTIME_MAP int efi_runtime_map_init(struct kobject *);