Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751937AbbLZPSd (ORCPT ); Sat, 26 Dec 2015 10:18:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44021 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751194AbbLZPSc (ORCPT ); Sat, 26 Dec 2015 10:18:32 -0500 Date: Sat, 26 Dec 2015 23:21:00 +0800 From: Minfei Huang To: Xunlei Pang Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org, akpm@linux-foundation.org, Eric Biederman Subject: Re: [PATCH 2/2] kexec: Provide arch_kexec_protect(unprotect)_crashkres() Message-ID: <20151226152100.GA26946@dhcp-128-25.nay.redhat.com> References: <1450869146-6186-1-git-send-email-xlpang@redhat.com> <1450869146-6186-2-git-send-email-xlpang@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1450869146-6186-2-git-send-email-xlpang@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1605 Lines: 51 On 12/23/15 at 07:12pm, Xunlei Pang wrote: > Implement the protection method for the crash kernel memory > reservation for the 64-bit x86 kdump. > > Signed-off-by: Xunlei Pang > --- > Only provided x86_64 implementation, as I've only tested on x86_64 so far. > > arch/x86/kernel/machine_kexec_64.c | 43 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c > index 819ab3f..a3d289c 100644 > --- a/arch/x86/kernel/machine_kexec_64.c > +++ b/arch/x86/kernel/machine_kexec_64.c > @@ -536,3 +536,46 @@ overflow: > return -ENOEXEC; > } > #endif /* CONFIG_KEXEC_FILE */ > + > +#ifdef CONFIG_KEXEC_CORE > +static int > +kexec_mark_range(unsigned long start, unsigned long end, bool protect) > +{ > + struct page *page; > + unsigned int nr_pages; > + > + if (!start || !end || start >= end) > + return 0; > + > + page = pfn_to_page(start >> PAGE_SHIFT); > + nr_pages = (end + 1 - start) >> PAGE_SHIFT; The start and end may across two pages, although the range is small than PAGE_SIZE. You can use following to calculate count of page. nr_pages = (end >> PAGE_SHIFT) - (start >> PAGE_SHIFT) + 1; Thanks Minfei > + if (protect) > + return set_pages_ro(page, nr_pages); > + else > + return set_pages_rw(page, nr_pages); > +} -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/