Skip to content

Commit 75b7c05

Browse files
ShivaprasadGBhatmpe
authored andcommitted
powerpc/papr_scm: Implement support for H_SCM_FLUSH hcall
Add support for ND_REGION_ASYNC capability if the device tree indicates 'ibm,hcall-flush-required' property in the NVDIMM node. Flush is done by issuing H_SCM_FLUSH hcall to the hypervisor. If the flush request failed, the hypervisor is expected to to reflect the problem in the subsequent nvdimm H_SCM_HEALTH call. This patch prevents mmap of namespaces with MAP_SYNC flag if the nvdimm requires an explicit flush[1]. References: [1] https://github.com/avocado-framework-tests/avocado-misc-tests/blob/master/memory/ndctl.py.data/map_sync.c Signed-off-by: Shivaprasad G Bhat <[email protected]> Reviewed-by: Aneesh Kumar K.V <[email protected]> [mpe: Use unsigned long / long instead of uint64_t/int64_t] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/161703936121.36.7260632399582101498.stgit@e1fbed493c87
1 parent af072b1 commit 75b7c05

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Documentation/powerpc/papr_hcalls.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,20 @@ Health Bitmap Flags:
275275
Given a DRC Index collect the performance statistics for NVDIMM and copy them
276276
to the resultBuffer.
277277

278+
**H_SCM_FLUSH**
279+
280+
| Input: *drcIndex, continue-token*
281+
| Out: *continue-token*
282+
| Return Value: *H_SUCCESS, H_Parameter, H_P2, H_BUSY*
283+
284+
Given a DRC Index Flush the data to backend NVDIMM device.
285+
286+
The hcall returns H_BUSY when the flush takes longer time and the hcall needs
287+
to be issued multiple times in order to be completely serviced. The
288+
*continue-token* from the output to be passed in the argument list of
289+
subsequent hcalls to the hypervisor until the hcall is completely serviced
290+
at which point H_SUCCESS or other error is returned by the hypervisor.
291+
278292
References
279293
==========
280294
.. [1] "Power Architecture Platform Reference"

arch/powerpc/include/asm/hvcall.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@
315315
#define H_SCM_HEALTH 0x400
316316
#define H_SCM_PERFORMANCE_STATS 0x418
317317
#define H_RPT_INVALIDATE 0x448
318-
#define MAX_HCALL_OPCODE H_RPT_INVALIDATE
318+
#define H_SCM_FLUSH 0x44C
319+
#define MAX_HCALL_OPCODE H_SCM_FLUSH
319320

320321
/* Scope args for H_SCM_UNBIND_ALL */
321322
#define H_UNBIND_SCOPE_ALL (0x1)

arch/powerpc/platforms/pseries/papr_scm.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct papr_scm_priv {
9393
uint64_t block_size;
9494
int metadata_size;
9595
bool is_volatile;
96+
bool hcall_flush_required;
9697

9798
uint64_t bound_addr;
9899

@@ -117,6 +118,38 @@ struct papr_scm_priv {
117118
size_t stat_buffer_len;
118119
};
119120

121+
static int papr_scm_pmem_flush(struct nd_region *nd_region,
122+
struct bio *bio __maybe_unused)
123+
{
124+
struct papr_scm_priv *p = nd_region_provider_data(nd_region);
125+
unsigned long ret_buf[PLPAR_HCALL_BUFSIZE], token = 0;
126+
long rc;
127+
128+
dev_dbg(&p->pdev->dev, "flush drc 0x%x", p->drc_index);
129+
130+
do {
131+
rc = plpar_hcall(H_SCM_FLUSH, ret_buf, p->drc_index, token);
132+
token = ret_buf[0];
133+
134+
/* Check if we are stalled for some time */
135+
if (H_IS_LONG_BUSY(rc)) {
136+
msleep(get_longbusy_msecs(rc));
137+
rc = H_BUSY;
138+
} else if (rc == H_BUSY) {
139+
cond_resched();
140+
}
141+
} while (rc == H_BUSY);
142+
143+
if (rc) {
144+
dev_err(&p->pdev->dev, "flush error: %lld", rc);
145+
rc = -EIO;
146+
} else {
147+
dev_dbg(&p->pdev->dev, "flush drc 0x%x complete", p->drc_index);
148+
}
149+
150+
return rc;
151+
}
152+
120153
static LIST_HEAD(papr_nd_regions);
121154
static DEFINE_MUTEX(papr_ndr_lock);
122155

@@ -943,6 +976,11 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
943976
ndr_desc.num_mappings = 1;
944977
ndr_desc.nd_set = &p->nd_set;
945978

979+
if (p->hcall_flush_required) {
980+
set_bit(ND_REGION_ASYNC, &ndr_desc.flags);
981+
ndr_desc.flush = papr_scm_pmem_flush;
982+
}
983+
946984
if (p->is_volatile)
947985
p->region = nvdimm_volatile_region_create(p->bus, &ndr_desc);
948986
else {
@@ -1088,6 +1126,7 @@ static int papr_scm_probe(struct platform_device *pdev)
10881126
p->block_size = block_size;
10891127
p->blocks = blocks;
10901128
p->is_volatile = !of_property_read_bool(dn, "ibm,cache-flush-required");
1129+
p->hcall_flush_required = of_property_read_bool(dn, "ibm,hcall-flush-required");
10911130

10921131
/* We just need to ensure that set cookies are unique across */
10931132
uuid_parse(uuid_str, (uuid_t *) uuid);

0 commit comments

Comments
 (0)